107742024-04-11 18:41:18mraronMetróutasokcpp17Accepted 100/10057ms7120 KiB
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;

int N;
vector<int> a;

ll solvemin() {
    auto chk = [&](ll lim) -> bool {
        ll mn = 0ll, mx = 0ll;
        for (int i=1; i<=N; ++i) {
            ll pmn = mn;
            if (mn >= a[i])
                mn -= a[i];
            else if (mx < a[i])
                mn = a[i]-mx;
            else
                mn = (mn+a[i]) % 2;

            if (mx+a[i] <= lim) mx += a[i];
            else {
                ll rem = lim-pmn;
                if ((pmn+a[i] <= lim) || (a[i] <= mx+lim))
                    mx = lim - (rem+a[i])%2;
                else return false;
            }
        }
        return (mn==0);
    };

    ll lo = 0, hi = accumulate(a.begin(), a.end(), 0ll);
    while (lo+1 < hi) {
        ll mid = (lo+hi)/2;
        if (chk(mid))
            hi = mid;
        else
            lo = mid;
    }
    return hi;
}
ll solvemax() {
    vector<ll> pref(N+1, 0ll);
    for (int i=1; i<=N; ++i)
        pref[i] = pref[i-1] + (ll)a[i];
    ll ans = 0ll, tot = 0ll;
    for (int i=N; i>0; --i) {
        tot += a[i];
        ans = max(ans, min(pref[i-1], tot));
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin >> N;
    a.assign(N+1, 0);
    for (int i=1; i<=N; ++i)
        cin >> a[i];
    
    cout << solvemin() << endl;
    cout << solvemax() << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2040 KiB
2Accepted57ms4436 KiB
subtask212/12
3Accepted3ms2268 KiB
4Accepted3ms2356 KiB
5Accepted3ms2592 KiB
6Accepted3ms2816 KiB
7Accepted3ms2900 KiB
8Accepted3ms2908 KiB
9Accepted2ms2996 KiB
10Accepted2ms2992 KiB
11Accepted3ms3220 KiB
12Accepted3ms3304 KiB
13Accepted2ms3208 KiB
14Accepted3ms3340 KiB
15Accepted3ms3564 KiB
16Accepted3ms3772 KiB
subtask312/12
17Accepted3ms2268 KiB
18Accepted3ms2356 KiB
19Accepted3ms2592 KiB
20Accepted3ms2816 KiB
21Accepted3ms2900 KiB
22Accepted3ms2908 KiB
23Accepted2ms2996 KiB
24Accepted2ms2992 KiB
25Accepted3ms3220 KiB
26Accepted3ms3304 KiB
27Accepted3ms3988 KiB
28Accepted3ms3840 KiB
29Accepted3ms3844 KiB
30Accepted3ms4072 KiB
31Accepted3ms4176 KiB
32Accepted2ms4272 KiB
33Accepted3ms4276 KiB
34Accepted3ms4360 KiB
35Accepted3ms4356 KiB
36Accepted3ms4360 KiB
37Accepted2ms3208 KiB
38Accepted3ms3340 KiB
39Accepted3ms4464 KiB
40Accepted3ms4480 KiB
41Accepted3ms4580 KiB
42Accepted3ms4752 KiB
43Accepted3ms3564 KiB
44Accepted3ms3772 KiB
45Accepted3ms4608 KiB
46Accepted3ms4528 KiB
47Accepted3ms4616 KiB
48Accepted3ms4648 KiB
49Accepted3ms4500 KiB
subtask416/16
50Accepted3ms2268 KiB
51Accepted3ms2356 KiB
52Accepted3ms2592 KiB
53Accepted3ms2816 KiB
54Accepted3ms2900 KiB
55Accepted3ms2908 KiB
56Accepted2ms2996 KiB
57Accepted2ms2992 KiB
58Accepted3ms3220 KiB
59Accepted3ms3304 KiB
60Accepted3ms3988 KiB
61Accepted3ms3840 KiB
62Accepted3ms3844 KiB
63Accepted3ms4072 KiB
64Accepted3ms4176 KiB
65Accepted2ms4272 KiB
66Accepted3ms4276 KiB
67Accepted3ms4360 KiB
68Accepted3ms4356 KiB
69Accepted3ms4360 KiB
70Accepted3ms4404 KiB
71Accepted3ms4404 KiB
72Accepted3ms4500 KiB
73Accepted3ms4400 KiB
74Accepted3ms4400 KiB
75Accepted2ms4400 KiB
76Accepted3ms4400 KiB
77Accepted3ms4680 KiB
78Accepted3ms4772 KiB
79Accepted3ms4856 KiB
80Accepted2ms3208 KiB
81Accepted3ms3340 KiB
82Accepted3ms4464 KiB
83Accepted3ms4480 KiB
84Accepted3ms4580 KiB
85Accepted3ms4752 KiB
86Accepted3ms3564 KiB
87Accepted3ms3772 KiB
88Accepted3ms4608 KiB
89Accepted3ms4528 KiB
90Accepted3ms4616 KiB
91Accepted3ms4648 KiB
92Accepted3ms4500 KiB
subtask560/60
93Accepted3ms2268 KiB
94Accepted57ms6864 KiB
95Accepted3ms2356 KiB
96Accepted3ms2592 KiB
97Accepted3ms2816 KiB
98Accepted3ms2900 KiB
99Accepted3ms2908 KiB
100Accepted2ms2996 KiB
101Accepted2ms2992 KiB
102Accepted3ms3220 KiB
103Accepted3ms3304 KiB
104Accepted3ms3988 KiB
105Accepted3ms3840 KiB
106Accepted3ms3844 KiB
107Accepted3ms4072 KiB
108Accepted3ms4176 KiB
109Accepted2ms4272 KiB
110Accepted3ms4276 KiB
111Accepted3ms4360 KiB
112Accepted3ms4356 KiB
113Accepted3ms4360 KiB
114Accepted3ms4404 KiB
115Accepted3ms4404 KiB
116Accepted3ms4500 KiB
117Accepted3ms4400 KiB
118Accepted3ms4400 KiB
119Accepted2ms4400 KiB
120Accepted3ms4400 KiB
121Accepted3ms4680 KiB
122Accepted3ms4772 KiB
123Accepted3ms4856 KiB
124Accepted34ms6864 KiB
125Accepted32ms6864 KiB
126Accepted37ms6920 KiB
127Accepted43ms6860 KiB
128Accepted35ms6940 KiB
129Accepted57ms6972 KiB
130Accepted46ms6860 KiB
131Accepted41ms6928 KiB
132Accepted57ms6988 KiB
133Accepted2ms3208 KiB
134Accepted3ms3340 KiB
135Accepted3ms4464 KiB
136Accepted3ms4480 KiB
137Accepted3ms4580 KiB
138Accepted3ms4752 KiB
139Accepted3ms3564 KiB
140Accepted3ms3772 KiB
141Accepted3ms4608 KiB
142Accepted3ms4528 KiB
143Accepted3ms4616 KiB
144Accepted20ms6728 KiB
145Accepted20ms6728 KiB
146Accepted24ms7120 KiB
147Accepted16ms6084 KiB
148Accepted23ms6728 KiB
149Accepted21ms6728 KiB
150Accepted3ms4648 KiB
151Accepted3ms4500 KiB
152Accepted20ms6732 KiB