10803 | 2024-04-14 13:12:06 | Ablablabla | Metróutasok | cpp17 | Partially correct 25/100 | 85ms | 6456 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 | 1748 KiB | ||||
2 | Partially correct | 85ms | 3264 KiB | ||||
subtask2 | 3/12 | ||||||
3 | Accepted | 3ms | 2244 KiB | ||||
4 | Accepted | 3ms | 2340 KiB | ||||
5 | Accepted | 3ms | 2544 KiB | ||||
6 | Accepted | 3ms | 2796 KiB | ||||
7 | Accepted | 3ms | 2852 KiB | ||||
8 | Accepted | 3ms | 2968 KiB | ||||
9 | Accepted | 3ms | 3188 KiB | ||||
10 | Accepted | 3ms | 3272 KiB | ||||
11 | Partially correct | 3ms | 3396 KiB | ||||
12 | Accepted | 3ms | 3480 KiB | ||||
13 | Accepted | 3ms | 3484 KiB | ||||
14 | Partially correct | 3ms | 3720 KiB | ||||
15 | Accepted | 3ms | 3868 KiB | ||||
16 | Accepted | 3ms | 3880 KiB | ||||
subtask3 | 3/12 | ||||||
17 | Accepted | 3ms | 2244 KiB | ||||
18 | Accepted | 3ms | 2340 KiB | ||||
19 | Accepted | 3ms | 2544 KiB | ||||
20 | Accepted | 3ms | 2796 KiB | ||||
21 | Accepted | 3ms | 2852 KiB | ||||
22 | Accepted | 3ms | 2968 KiB | ||||
23 | Accepted | 3ms | 3188 KiB | ||||
24 | Accepted | 3ms | 3272 KiB | ||||
25 | Partially correct | 3ms | 3396 KiB | ||||
26 | Accepted | 3ms | 3480 KiB | ||||
27 | Accepted | 3ms | 3892 KiB | ||||
28 | Accepted | 3ms | 3892 KiB | ||||
29 | Accepted | 3ms | 3892 KiB | ||||
30 | Accepted | 3ms | 4040 KiB | ||||
31 | Accepted | 3ms | 4036 KiB | ||||
32 | Accepted | 3ms | 4152 KiB | ||||
33 | Accepted | 3ms | 4148 KiB | ||||
34 | Accepted | 3ms | 4152 KiB | ||||
35 | Accepted | 3ms | 4100 KiB | ||||
36 | Accepted | 3ms | 4212 KiB | ||||
37 | Accepted | 3ms | 3484 KiB | ||||
38 | Partially correct | 3ms | 3720 KiB | ||||
39 | Partially correct | 3ms | 4216 KiB | ||||
40 | Partially correct | 3ms | 4212 KiB | ||||
41 | Partially correct | 3ms | 4344 KiB | ||||
42 | Partially correct | 3ms | 4432 KiB | ||||
43 | Accepted | 3ms | 3868 KiB | ||||
44 | Accepted | 3ms | 3880 KiB | ||||
45 | Partially correct | 3ms | 4424 KiB | ||||
46 | Partially correct | 3ms | 4428 KiB | ||||
47 | Partially correct | 3ms | 4540 KiB | ||||
48 | Accepted | 3ms | 4564 KiB | ||||
49 | Partially correct | 3ms | 4332 KiB | ||||
subtask4 | 4/16 | ||||||
50 | Accepted | 3ms | 2244 KiB | ||||
51 | Accepted | 3ms | 2340 KiB | ||||
52 | Accepted | 3ms | 2544 KiB | ||||
53 | Accepted | 3ms | 2796 KiB | ||||
54 | Accepted | 3ms | 2852 KiB | ||||
55 | Accepted | 3ms | 2968 KiB | ||||
56 | Accepted | 3ms | 3188 KiB | ||||
57 | Accepted | 3ms | 3272 KiB | ||||
58 | Partially correct | 3ms | 3396 KiB | ||||
59 | Accepted | 3ms | 3480 KiB | ||||
60 | Accepted | 3ms | 3892 KiB | ||||
61 | Accepted | 3ms | 3892 KiB | ||||
62 | Accepted | 3ms | 3892 KiB | ||||
63 | Accepted | 3ms | 4040 KiB | ||||
64 | Accepted | 3ms | 4036 KiB | ||||
65 | Accepted | 3ms | 4152 KiB | ||||
66 | Accepted | 3ms | 4148 KiB | ||||
67 | Accepted | 3ms | 4152 KiB | ||||
68 | Accepted | 3ms | 4100 KiB | ||||
69 | Accepted | 3ms | 4212 KiB | ||||
70 | Partially correct | 3ms | 4488 KiB | ||||
71 | Accepted | 3ms | 4508 KiB | ||||
72 | Accepted | 3ms | 4528 KiB | ||||
73 | Accepted | 3ms | 4488 KiB | ||||
74 | Accepted | 3ms | 4492 KiB | ||||
75 | Accepted | 3ms | 4680 KiB | ||||
76 | Accepted | 3ms | 4892 KiB | ||||
77 | Partially correct | 3ms | 4948 KiB | ||||
78 | Accepted | 3ms | 4960 KiB | ||||
79 | Accepted | 3ms | 5068 KiB | ||||
80 | Accepted | 3ms | 3484 KiB | ||||
81 | Partially correct | 3ms | 3720 KiB | ||||
82 | Partially correct | 3ms | 4216 KiB | ||||
83 | Partially correct | 3ms | 4212 KiB | ||||
84 | Partially correct | 3ms | 4344 KiB | ||||
85 | Partially correct | 3ms | 4432 KiB | ||||
86 | Accepted | 3ms | 3868 KiB | ||||
87 | Accepted | 3ms | 3880 KiB | ||||
88 | Partially correct | 3ms | 4424 KiB | ||||
89 | Partially correct | 3ms | 4428 KiB | ||||
90 | Partially correct | 3ms | 4540 KiB | ||||
91 | Accepted | 3ms | 4564 KiB | ||||
92 | Partially correct | 3ms | 4332 KiB | ||||
subtask5 | 15/60 | ||||||
93 | Accepted | 3ms | 2244 KiB | ||||
94 | Partially correct | 85ms | 6456 KiB | ||||
95 | Accepted | 3ms | 2340 KiB | ||||
96 | Accepted | 3ms | 2544 KiB | ||||
97 | Accepted | 3ms | 2796 KiB | ||||
98 | Accepted | 3ms | 2852 KiB | ||||
99 | Accepted | 3ms | 2968 KiB | ||||
100 | Accepted | 3ms | 3188 KiB | ||||
101 | Accepted | 3ms | 3272 KiB | ||||
102 | Partially correct | 3ms | 3396 KiB | ||||
103 | Accepted | 3ms | 3480 KiB | ||||
104 | Accepted | 3ms | 3892 KiB | ||||
105 | Accepted | 3ms | 3892 KiB | ||||
106 | Accepted | 3ms | 3892 KiB | ||||
107 | Accepted | 3ms | 4040 KiB | ||||
108 | Accepted | 3ms | 4036 KiB | ||||
109 | Accepted | 3ms | 4152 KiB | ||||
110 | Accepted | 3ms | 4148 KiB | ||||
111 | Accepted | 3ms | 4152 KiB | ||||
112 | Accepted | 3ms | 4100 KiB | ||||
113 | Accepted | 3ms | 4212 KiB | ||||
114 | Partially correct | 3ms | 4488 KiB | ||||
115 | Accepted | 3ms | 4508 KiB | ||||
116 | Accepted | 3ms | 4528 KiB | ||||
117 | Accepted | 3ms | 4488 KiB | ||||
118 | Accepted | 3ms | 4492 KiB | ||||
119 | Accepted | 3ms | 4680 KiB | ||||
120 | Accepted | 3ms | 4892 KiB | ||||
121 | Partially correct | 3ms | 4948 KiB | ||||
122 | Accepted | 3ms | 4960 KiB | ||||
123 | Accepted | 3ms | 5068 KiB | ||||
124 | Accepted | 65ms | 6304 KiB | ||||
125 | Accepted | 67ms | 6304 KiB | ||||
126 | Accepted | 70ms | 6304 KiB | ||||
127 | Accepted | 67ms | 6456 KiB | ||||
128 | Accepted | 68ms | 6308 KiB | ||||
129 | Partially correct | 82ms | 6388 KiB | ||||
130 | Partially correct | 70ms | 6308 KiB | ||||
131 | Accepted | 65ms | 6304 KiB | ||||
132 | Accepted | 83ms | 6308 KiB | ||||
133 | Accepted | 3ms | 3484 KiB | ||||
134 | Partially correct | 3ms | 3720 KiB | ||||
135 | Partially correct | 3ms | 4216 KiB | ||||
136 | Partially correct | 3ms | 4212 KiB | ||||
137 | Partially correct | 3ms | 4344 KiB | ||||
138 | Partially correct | 3ms | 4432 KiB | ||||
139 | Accepted | 3ms | 3868 KiB | ||||
140 | Accepted | 3ms | 3880 KiB | ||||
141 | Partially correct | 3ms | 4424 KiB | ||||
142 | Partially correct | 3ms | 4428 KiB | ||||
143 | Partially correct | 3ms | 4540 KiB | ||||
144 | Partially correct | 35ms | 6176 KiB | ||||
145 | Partially correct | 32ms | 6180 KiB | ||||
146 | Partially correct | 37ms | 6388 KiB | ||||
147 | Accepted | 24ms | 5740 KiB | ||||
148 | Partially correct | 35ms | 6180 KiB | ||||
149 | Partially correct | 32ms | 6176 KiB | ||||
150 | Accepted | 3ms | 4564 KiB | ||||
151 | Partially correct | 3ms | 4332 KiB | ||||
152 | Accepted | 32ms | 6212 KiB |