10774 | 2024-04-11 18:41:18 | mraron | Metróutasok | cpp17 | Accepted 100/100 | 57ms | 7120 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2040 KiB | ||||
2 | Accepted | 57ms | 4436 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2268 KiB | ||||
4 | Accepted | 3ms | 2356 KiB | ||||
5 | Accepted | 3ms | 2592 KiB | ||||
6 | Accepted | 3ms | 2816 KiB | ||||
7 | Accepted | 3ms | 2900 KiB | ||||
8 | Accepted | 3ms | 2908 KiB | ||||
9 | Accepted | 2ms | 2996 KiB | ||||
10 | Accepted | 2ms | 2992 KiB | ||||
11 | Accepted | 3ms | 3220 KiB | ||||
12 | Accepted | 3ms | 3304 KiB | ||||
13 | Accepted | 2ms | 3208 KiB | ||||
14 | Accepted | 3ms | 3340 KiB | ||||
15 | Accepted | 3ms | 3564 KiB | ||||
16 | Accepted | 3ms | 3772 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 3ms | 2268 KiB | ||||
18 | Accepted | 3ms | 2356 KiB | ||||
19 | Accepted | 3ms | 2592 KiB | ||||
20 | Accepted | 3ms | 2816 KiB | ||||
21 | Accepted | 3ms | 2900 KiB | ||||
22 | Accepted | 3ms | 2908 KiB | ||||
23 | Accepted | 2ms | 2996 KiB | ||||
24 | Accepted | 2ms | 2992 KiB | ||||
25 | Accepted | 3ms | 3220 KiB | ||||
26 | Accepted | 3ms | 3304 KiB | ||||
27 | Accepted | 3ms | 3988 KiB | ||||
28 | Accepted | 3ms | 3840 KiB | ||||
29 | Accepted | 3ms | 3844 KiB | ||||
30 | Accepted | 3ms | 4072 KiB | ||||
31 | Accepted | 3ms | 4176 KiB | ||||
32 | Accepted | 2ms | 4272 KiB | ||||
33 | Accepted | 3ms | 4276 KiB | ||||
34 | Accepted | 3ms | 4360 KiB | ||||
35 | Accepted | 3ms | 4356 KiB | ||||
36 | Accepted | 3ms | 4360 KiB | ||||
37 | Accepted | 2ms | 3208 KiB | ||||
38 | Accepted | 3ms | 3340 KiB | ||||
39 | Accepted | 3ms | 4464 KiB | ||||
40 | Accepted | 3ms | 4480 KiB | ||||
41 | Accepted | 3ms | 4580 KiB | ||||
42 | Accepted | 3ms | 4752 KiB | ||||
43 | Accepted | 3ms | 3564 KiB | ||||
44 | Accepted | 3ms | 3772 KiB | ||||
45 | Accepted | 3ms | 4608 KiB | ||||
46 | Accepted | 3ms | 4528 KiB | ||||
47 | Accepted | 3ms | 4616 KiB | ||||
48 | Accepted | 3ms | 4648 KiB | ||||
49 | Accepted | 3ms | 4500 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 3ms | 2268 KiB | ||||
51 | Accepted | 3ms | 2356 KiB | ||||
52 | Accepted | 3ms | 2592 KiB | ||||
53 | Accepted | 3ms | 2816 KiB | ||||
54 | Accepted | 3ms | 2900 KiB | ||||
55 | Accepted | 3ms | 2908 KiB | ||||
56 | Accepted | 2ms | 2996 KiB | ||||
57 | Accepted | 2ms | 2992 KiB | ||||
58 | Accepted | 3ms | 3220 KiB | ||||
59 | Accepted | 3ms | 3304 KiB | ||||
60 | Accepted | 3ms | 3988 KiB | ||||
61 | Accepted | 3ms | 3840 KiB | ||||
62 | Accepted | 3ms | 3844 KiB | ||||
63 | Accepted | 3ms | 4072 KiB | ||||
64 | Accepted | 3ms | 4176 KiB | ||||
65 | Accepted | 2ms | 4272 KiB | ||||
66 | Accepted | 3ms | 4276 KiB | ||||
67 | Accepted | 3ms | 4360 KiB | ||||
68 | Accepted | 3ms | 4356 KiB | ||||
69 | Accepted | 3ms | 4360 KiB | ||||
70 | Accepted | 3ms | 4404 KiB | ||||
71 | Accepted | 3ms | 4404 KiB | ||||
72 | Accepted | 3ms | 4500 KiB | ||||
73 | Accepted | 3ms | 4400 KiB | ||||
74 | Accepted | 3ms | 4400 KiB | ||||
75 | Accepted | 2ms | 4400 KiB | ||||
76 | Accepted | 3ms | 4400 KiB | ||||
77 | Accepted | 3ms | 4680 KiB | ||||
78 | Accepted | 3ms | 4772 KiB | ||||
79 | Accepted | 3ms | 4856 KiB | ||||
80 | Accepted | 2ms | 3208 KiB | ||||
81 | Accepted | 3ms | 3340 KiB | ||||
82 | Accepted | 3ms | 4464 KiB | ||||
83 | Accepted | 3ms | 4480 KiB | ||||
84 | Accepted | 3ms | 4580 KiB | ||||
85 | Accepted | 3ms | 4752 KiB | ||||
86 | Accepted | 3ms | 3564 KiB | ||||
87 | Accepted | 3ms | 3772 KiB | ||||
88 | Accepted | 3ms | 4608 KiB | ||||
89 | Accepted | 3ms | 4528 KiB | ||||
90 | Accepted | 3ms | 4616 KiB | ||||
91 | Accepted | 3ms | 4648 KiB | ||||
92 | Accepted | 3ms | 4500 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 3ms | 2268 KiB | ||||
94 | Accepted | 57ms | 6864 KiB | ||||
95 | Accepted | 3ms | 2356 KiB | ||||
96 | Accepted | 3ms | 2592 KiB | ||||
97 | Accepted | 3ms | 2816 KiB | ||||
98 | Accepted | 3ms | 2900 KiB | ||||
99 | Accepted | 3ms | 2908 KiB | ||||
100 | Accepted | 2ms | 2996 KiB | ||||
101 | Accepted | 2ms | 2992 KiB | ||||
102 | Accepted | 3ms | 3220 KiB | ||||
103 | Accepted | 3ms | 3304 KiB | ||||
104 | Accepted | 3ms | 3988 KiB | ||||
105 | Accepted | 3ms | 3840 KiB | ||||
106 | Accepted | 3ms | 3844 KiB | ||||
107 | Accepted | 3ms | 4072 KiB | ||||
108 | Accepted | 3ms | 4176 KiB | ||||
109 | Accepted | 2ms | 4272 KiB | ||||
110 | Accepted | 3ms | 4276 KiB | ||||
111 | Accepted | 3ms | 4360 KiB | ||||
112 | Accepted | 3ms | 4356 KiB | ||||
113 | Accepted | 3ms | 4360 KiB | ||||
114 | Accepted | 3ms | 4404 KiB | ||||
115 | Accepted | 3ms | 4404 KiB | ||||
116 | Accepted | 3ms | 4500 KiB | ||||
117 | Accepted | 3ms | 4400 KiB | ||||
118 | Accepted | 3ms | 4400 KiB | ||||
119 | Accepted | 2ms | 4400 KiB | ||||
120 | Accepted | 3ms | 4400 KiB | ||||
121 | Accepted | 3ms | 4680 KiB | ||||
122 | Accepted | 3ms | 4772 KiB | ||||
123 | Accepted | 3ms | 4856 KiB | ||||
124 | Accepted | 34ms | 6864 KiB | ||||
125 | Accepted | 32ms | 6864 KiB | ||||
126 | Accepted | 37ms | 6920 KiB | ||||
127 | Accepted | 43ms | 6860 KiB | ||||
128 | Accepted | 35ms | 6940 KiB | ||||
129 | Accepted | 57ms | 6972 KiB | ||||
130 | Accepted | 46ms | 6860 KiB | ||||
131 | Accepted | 41ms | 6928 KiB | ||||
132 | Accepted | 57ms | 6988 KiB | ||||
133 | Accepted | 2ms | 3208 KiB | ||||
134 | Accepted | 3ms | 3340 KiB | ||||
135 | Accepted | 3ms | 4464 KiB | ||||
136 | Accepted | 3ms | 4480 KiB | ||||
137 | Accepted | 3ms | 4580 KiB | ||||
138 | Accepted | 3ms | 4752 KiB | ||||
139 | Accepted | 3ms | 3564 KiB | ||||
140 | Accepted | 3ms | 3772 KiB | ||||
141 | Accepted | 3ms | 4608 KiB | ||||
142 | Accepted | 3ms | 4528 KiB | ||||
143 | Accepted | 3ms | 4616 KiB | ||||
144 | Accepted | 20ms | 6728 KiB | ||||
145 | Accepted | 20ms | 6728 KiB | ||||
146 | Accepted | 24ms | 7120 KiB | ||||
147 | Accepted | 16ms | 6084 KiB | ||||
148 | Accepted | 23ms | 6728 KiB | ||||
149 | Accepted | 21ms | 6728 KiB | ||||
150 | Accepted | 3ms | 4648 KiB | ||||
151 | Accepted | 3ms | 4500 KiB | ||||
152 | Accepted | 20ms | 6732 KiB |