10804 | 2024-04-14 13:14:20 | Ablablabla | Metróutasok | cpp17 | Accepted 100/100 | 82ms | 6728 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<ll> szamok;
ll ossz = 0;
bool check(ll hatar){
ll mn = 0;
ll mx = 0;
for(int i = 0; i < n; i++){
ll mas = mn;
if(mn >= szamok[i]){
mn -= szamok[i];
} else if(mx < szamok[i]){
mn = szamok[i] - mx;
} else{
mn = (mn + szamok[i]) % 2;
}
if(mx + szamok[i] <= hatar){
mx += szamok[i];
} else{
ll marad = hatar - mas;
if((mas + szamok[i] <= hatar) || (szamok[i] <= mx + hatar)){
mx = hatar - (marad + szamok[i]) % 2;
} else{
return false;
}
}
}
return (mn == 0);
}
void minKer(){
ll l = max(szamok[0], szamok[n - 1]), r = ossz;
ll ans = 0;
while(l <= r){
ll k = (l + r) / 2;
if(check(k)){
ans = k;
r = k - 1;
} else{
l = k + 1;
}
}
cout << ans << "\n";
}
void maxKer(){
ll fent = 0;
ll fel = 0;
ll maxi = 0;
for(int i = 0; i < n; i++){
ll felszall = min(szamok[i], ossz / 2 - fel);
ll leszall = szamok[i] - felszall;
fent += felszall - leszall;
fel += felszall;
maxi = max(maxi, fent);
}
cout << maxi << "\n";
}
int main()
{
cin >> n;
szamok.assign(n, 0);
for(ll &x : szamok){
cin >> x;
ossz += x;
}
minKer();
maxKer();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1876 KiB | ||||
2 | Accepted | 82ms | 3468 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2204 KiB | ||||
4 | Accepted | 3ms | 2276 KiB | ||||
5 | Accepted | 3ms | 2492 KiB | ||||
6 | Accepted | 3ms | 2840 KiB | ||||
7 | Accepted | 3ms | 2788 KiB | ||||
8 | Accepted | 3ms | 2792 KiB | ||||
9 | Accepted | 3ms | 2992 KiB | ||||
10 | Accepted | 3ms | 3156 KiB | ||||
11 | Accepted | 3ms | 3244 KiB | ||||
12 | Accepted | 2ms | 3184 KiB | ||||
13 | Accepted | 2ms | 3072 KiB | ||||
14 | Accepted | 3ms | 3072 KiB | ||||
15 | Accepted | 3ms | 3320 KiB | ||||
16 | Accepted | 3ms | 3284 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 3ms | 2204 KiB | ||||
18 | Accepted | 3ms | 2276 KiB | ||||
19 | Accepted | 3ms | 2492 KiB | ||||
20 | Accepted | 3ms | 2840 KiB | ||||
21 | Accepted | 3ms | 2788 KiB | ||||
22 | Accepted | 3ms | 2792 KiB | ||||
23 | Accepted | 3ms | 2992 KiB | ||||
24 | Accepted | 3ms | 3156 KiB | ||||
25 | Accepted | 3ms | 3244 KiB | ||||
26 | Accepted | 2ms | 3184 KiB | ||||
27 | Accepted | 3ms | 3284 KiB | ||||
28 | Accepted | 3ms | 3420 KiB | ||||
29 | Accepted | 3ms | 3544 KiB | ||||
30 | Accepted | 3ms | 3640 KiB | ||||
31 | Accepted | 3ms | 3852 KiB | ||||
32 | Accepted | 3ms | 4240 KiB | ||||
33 | Accepted | 3ms | 4156 KiB | ||||
34 | Accepted | 3ms | 4284 KiB | ||||
35 | Accepted | 3ms | 4408 KiB | ||||
36 | Accepted | 3ms | 4560 KiB | ||||
37 | Accepted | 2ms | 3072 KiB | ||||
38 | Accepted | 3ms | 3072 KiB | ||||
39 | Accepted | 3ms | 4560 KiB | ||||
40 | Accepted | 3ms | 4688 KiB | ||||
41 | Accepted | 3ms | 4572 KiB | ||||
42 | Accepted | 3ms | 4692 KiB | ||||
43 | Accepted | 3ms | 3320 KiB | ||||
44 | Accepted | 3ms | 3284 KiB | ||||
45 | Accepted | 3ms | 4664 KiB | ||||
46 | Accepted | 3ms | 4664 KiB | ||||
47 | Accepted | 3ms | 4664 KiB | ||||
48 | Accepted | 2ms | 4664 KiB | ||||
49 | Accepted | 3ms | 4784 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 3ms | 2204 KiB | ||||
51 | Accepted | 3ms | 2276 KiB | ||||
52 | Accepted | 3ms | 2492 KiB | ||||
53 | Accepted | 3ms | 2840 KiB | ||||
54 | Accepted | 3ms | 2788 KiB | ||||
55 | Accepted | 3ms | 2792 KiB | ||||
56 | Accepted | 3ms | 2992 KiB | ||||
57 | Accepted | 3ms | 3156 KiB | ||||
58 | Accepted | 3ms | 3244 KiB | ||||
59 | Accepted | 2ms | 3184 KiB | ||||
60 | Accepted | 3ms | 3284 KiB | ||||
61 | Accepted | 3ms | 3420 KiB | ||||
62 | Accepted | 3ms | 3544 KiB | ||||
63 | Accepted | 3ms | 3640 KiB | ||||
64 | Accepted | 3ms | 3852 KiB | ||||
65 | Accepted | 3ms | 4240 KiB | ||||
66 | Accepted | 3ms | 4156 KiB | ||||
67 | Accepted | 3ms | 4284 KiB | ||||
68 | Accepted | 3ms | 4408 KiB | ||||
69 | Accepted | 3ms | 4560 KiB | ||||
70 | Accepted | 3ms | 4668 KiB | ||||
71 | Accepted | 3ms | 4668 KiB | ||||
72 | Accepted | 3ms | 4800 KiB | ||||
73 | Accepted | 3ms | 4812 KiB | ||||
74 | Accepted | 3ms | 4812 KiB | ||||
75 | Accepted | 3ms | 4812 KiB | ||||
76 | Accepted | 3ms | 4808 KiB | ||||
77 | Accepted | 3ms | 4804 KiB | ||||
78 | Accepted | 3ms | 4804 KiB | ||||
79 | Accepted | 3ms | 4804 KiB | ||||
80 | Accepted | 2ms | 3072 KiB | ||||
81 | Accepted | 3ms | 3072 KiB | ||||
82 | Accepted | 3ms | 4560 KiB | ||||
83 | Accepted | 3ms | 4688 KiB | ||||
84 | Accepted | 3ms | 4572 KiB | ||||
85 | Accepted | 3ms | 4692 KiB | ||||
86 | Accepted | 3ms | 3320 KiB | ||||
87 | Accepted | 3ms | 3284 KiB | ||||
88 | Accepted | 3ms | 4664 KiB | ||||
89 | Accepted | 3ms | 4664 KiB | ||||
90 | Accepted | 3ms | 4664 KiB | ||||
91 | Accepted | 2ms | 4664 KiB | ||||
92 | Accepted | 3ms | 4784 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 3ms | 2204 KiB | ||||
94 | Accepted | 82ms | 6160 KiB | ||||
95 | Accepted | 3ms | 2276 KiB | ||||
96 | Accepted | 3ms | 2492 KiB | ||||
97 | Accepted | 3ms | 2840 KiB | ||||
98 | Accepted | 3ms | 2788 KiB | ||||
99 | Accepted | 3ms | 2792 KiB | ||||
100 | Accepted | 3ms | 2992 KiB | ||||
101 | Accepted | 3ms | 3156 KiB | ||||
102 | Accepted | 3ms | 3244 KiB | ||||
103 | Accepted | 2ms | 3184 KiB | ||||
104 | Accepted | 3ms | 3284 KiB | ||||
105 | Accepted | 3ms | 3420 KiB | ||||
106 | Accepted | 3ms | 3544 KiB | ||||
107 | Accepted | 3ms | 3640 KiB | ||||
108 | Accepted | 3ms | 3852 KiB | ||||
109 | Accepted | 3ms | 4240 KiB | ||||
110 | Accepted | 3ms | 4156 KiB | ||||
111 | Accepted | 3ms | 4284 KiB | ||||
112 | Accepted | 3ms | 4408 KiB | ||||
113 | Accepted | 3ms | 4560 KiB | ||||
114 | Accepted | 3ms | 4668 KiB | ||||
115 | Accepted | 3ms | 4668 KiB | ||||
116 | Accepted | 3ms | 4800 KiB | ||||
117 | Accepted | 3ms | 4812 KiB | ||||
118 | Accepted | 3ms | 4812 KiB | ||||
119 | Accepted | 3ms | 4812 KiB | ||||
120 | Accepted | 3ms | 4808 KiB | ||||
121 | Accepted | 3ms | 4804 KiB | ||||
122 | Accepted | 3ms | 4804 KiB | ||||
123 | Accepted | 3ms | 4804 KiB | ||||
124 | Accepted | 65ms | 6288 KiB | ||||
125 | Accepted | 65ms | 6384 KiB | ||||
126 | Accepted | 68ms | 6468 KiB | ||||
127 | Accepted | 64ms | 6476 KiB | ||||
128 | Accepted | 67ms | 6460 KiB | ||||
129 | Accepted | 79ms | 6380 KiB | ||||
130 | Accepted | 68ms | 6376 KiB | ||||
131 | Accepted | 64ms | 6376 KiB | ||||
132 | Accepted | 81ms | 6528 KiB | ||||
133 | Accepted | 2ms | 3072 KiB | ||||
134 | Accepted | 3ms | 3072 KiB | ||||
135 | Accepted | 3ms | 4560 KiB | ||||
136 | Accepted | 3ms | 4688 KiB | ||||
137 | Accepted | 3ms | 4572 KiB | ||||
138 | Accepted | 3ms | 4692 KiB | ||||
139 | Accepted | 3ms | 3320 KiB | ||||
140 | Accepted | 3ms | 3284 KiB | ||||
141 | Accepted | 3ms | 4664 KiB | ||||
142 | Accepted | 3ms | 4664 KiB | ||||
143 | Accepted | 3ms | 4664 KiB | ||||
144 | Accepted | 35ms | 6488 KiB | ||||
145 | Accepted | 32ms | 6620 KiB | ||||
146 | Accepted | 37ms | 6728 KiB | ||||
147 | Accepted | 24ms | 5988 KiB | ||||
148 | Accepted | 35ms | 6452 KiB | ||||
149 | Accepted | 32ms | 6452 KiB | ||||
150 | Accepted | 2ms | 4664 KiB | ||||
151 | Accepted | 3ms | 4784 KiB | ||||
152 | Accepted | 32ms | 6600 KiB |