10960 | 2024-04-20 19:18:44 | k_balint | Metróutasok | cpp17 | Accepted 100/100 | 63ms | 8520 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int c=2e5+5;
int n;
ll arr[c];
ll suf[c];
bool check(ll k){
ll cur=0;
for(int i=1;i<=n;i++){
ll le=(cur+arr[i]-k+1)/2;
if(le>min(arr[i],cur)) return 0;
cur=cur+arr[i]-2*max(0ll,le);
}
return 1;
}
bool jo(ll k){
bool res = check(k);
reverse(arr+1,arr+n+1);
res &= check(k);
reverse(arr+1,arr+n+1);
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
ll l=0,r=1e15;
while(l<r-1){
ll mid=l+r>>1;
if(jo(mid)) r=mid;
else l=mid;
}
cout << r << endl;
for(int i=n;i>0;i--) suf[i]=suf[i+1]+arr[i];
ll sum=0;
ll maxi=0;
for(int i=1;i<=n;i++){
if(suf[i+1]>=sum+arr[i]){
sum+=arr[i];
maxi=sum;
}
else{
maxi=max(suf[i+1],maxi);
break;
}
}
cout << maxi << endl;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2180 KiB | ||||
2 | Accepted | 59ms | 5448 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2480 KiB | ||||
4 | Accepted | 3ms | 2436 KiB | ||||
5 | Accepted | 3ms | 2692 KiB | ||||
6 | Accepted | 3ms | 2904 KiB | ||||
7 | Accepted | 3ms | 2984 KiB | ||||
8 | Accepted | 3ms | 3120 KiB | ||||
9 | Accepted | 3ms | 3332 KiB | ||||
10 | Accepted | 3ms | 3408 KiB | ||||
11 | Accepted | 3ms | 3376 KiB | ||||
12 | Accepted | 3ms | 3452 KiB | ||||
13 | Accepted | 3ms | 3592 KiB | ||||
14 | Accepted | 3ms | 3596 KiB | ||||
15 | Accepted | 3ms | 3820 KiB | ||||
16 | Accepted | 3ms | 4020 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 3ms | 2480 KiB | ||||
18 | Accepted | 3ms | 2436 KiB | ||||
19 | Accepted | 3ms | 2692 KiB | ||||
20 | Accepted | 3ms | 2904 KiB | ||||
21 | Accepted | 3ms | 2984 KiB | ||||
22 | Accepted | 3ms | 3120 KiB | ||||
23 | Accepted | 3ms | 3332 KiB | ||||
24 | Accepted | 3ms | 3408 KiB | ||||
25 | Accepted | 3ms | 3376 KiB | ||||
26 | Accepted | 3ms | 3452 KiB | ||||
27 | Accepted | 3ms | 3956 KiB | ||||
28 | Accepted | 3ms | 3928 KiB | ||||
29 | Accepted | 3ms | 3808 KiB | ||||
30 | Accepted | 3ms | 3804 KiB | ||||
31 | Accepted | 3ms | 4016 KiB | ||||
32 | Accepted | 3ms | 4212 KiB | ||||
33 | Accepted | 3ms | 4292 KiB | ||||
34 | Accepted | 3ms | 4296 KiB | ||||
35 | Accepted | 3ms | 4220 KiB | ||||
36 | Accepted | 3ms | 4140 KiB | ||||
37 | Accepted | 3ms | 3592 KiB | ||||
38 | Accepted | 3ms | 3596 KiB | ||||
39 | Accepted | 3ms | 4228 KiB | ||||
40 | Accepted | 3ms | 4136 KiB | ||||
41 | Accepted | 3ms | 4228 KiB | ||||
42 | Accepted | 3ms | 4144 KiB | ||||
43 | Accepted | 3ms | 3820 KiB | ||||
44 | Accepted | 3ms | 4020 KiB | ||||
45 | Accepted | 3ms | 4140 KiB | ||||
46 | Accepted | 3ms | 4136 KiB | ||||
47 | Accepted | 3ms | 4464 KiB | ||||
48 | Accepted | 3ms | 4560 KiB | ||||
49 | Accepted | 3ms | 4652 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 3ms | 2480 KiB | ||||
51 | Accepted | 3ms | 2436 KiB | ||||
52 | Accepted | 3ms | 2692 KiB | ||||
53 | Accepted | 3ms | 2904 KiB | ||||
54 | Accepted | 3ms | 2984 KiB | ||||
55 | Accepted | 3ms | 3120 KiB | ||||
56 | Accepted | 3ms | 3332 KiB | ||||
57 | Accepted | 3ms | 3408 KiB | ||||
58 | Accepted | 3ms | 3376 KiB | ||||
59 | Accepted | 3ms | 3452 KiB | ||||
60 | Accepted | 3ms | 3956 KiB | ||||
61 | Accepted | 3ms | 3928 KiB | ||||
62 | Accepted | 3ms | 3808 KiB | ||||
63 | Accepted | 3ms | 3804 KiB | ||||
64 | Accepted | 3ms | 4016 KiB | ||||
65 | Accepted | 3ms | 4212 KiB | ||||
66 | Accepted | 3ms | 4292 KiB | ||||
67 | Accepted | 3ms | 4296 KiB | ||||
68 | Accepted | 3ms | 4220 KiB | ||||
69 | Accepted | 3ms | 4140 KiB | ||||
70 | Accepted | 3ms | 4888 KiB | ||||
71 | Accepted | 3ms | 4980 KiB | ||||
72 | Accepted | 3ms | 4936 KiB | ||||
73 | Accepted | 3ms | 4988 KiB | ||||
74 | Accepted | 3ms | 4992 KiB | ||||
75 | Accepted | 3ms | 4940 KiB | ||||
76 | Accepted | 3ms | 4948 KiB | ||||
77 | Accepted | 3ms | 5016 KiB | ||||
78 | Accepted | 3ms | 5272 KiB | ||||
79 | Accepted | 3ms | 5152 KiB | ||||
80 | Accepted | 3ms | 3592 KiB | ||||
81 | Accepted | 3ms | 3596 KiB | ||||
82 | Accepted | 3ms | 4228 KiB | ||||
83 | Accepted | 3ms | 4136 KiB | ||||
84 | Accepted | 3ms | 4228 KiB | ||||
85 | Accepted | 3ms | 4144 KiB | ||||
86 | Accepted | 3ms | 3820 KiB | ||||
87 | Accepted | 3ms | 4020 KiB | ||||
88 | Accepted | 3ms | 4140 KiB | ||||
89 | Accepted | 3ms | 4136 KiB | ||||
90 | Accepted | 3ms | 4464 KiB | ||||
91 | Accepted | 3ms | 4560 KiB | ||||
92 | Accepted | 3ms | 4652 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 3ms | 2480 KiB | ||||
94 | Accepted | 59ms | 8412 KiB | ||||
95 | Accepted | 3ms | 2436 KiB | ||||
96 | Accepted | 3ms | 2692 KiB | ||||
97 | Accepted | 3ms | 2904 KiB | ||||
98 | Accepted | 3ms | 2984 KiB | ||||
99 | Accepted | 3ms | 3120 KiB | ||||
100 | Accepted | 3ms | 3332 KiB | ||||
101 | Accepted | 3ms | 3408 KiB | ||||
102 | Accepted | 3ms | 3376 KiB | ||||
103 | Accepted | 3ms | 3452 KiB | ||||
104 | Accepted | 3ms | 3956 KiB | ||||
105 | Accepted | 3ms | 3928 KiB | ||||
106 | Accepted | 3ms | 3808 KiB | ||||
107 | Accepted | 3ms | 3804 KiB | ||||
108 | Accepted | 3ms | 4016 KiB | ||||
109 | Accepted | 3ms | 4212 KiB | ||||
110 | Accepted | 3ms | 4292 KiB | ||||
111 | Accepted | 3ms | 4296 KiB | ||||
112 | Accepted | 3ms | 4220 KiB | ||||
113 | Accepted | 3ms | 4140 KiB | ||||
114 | Accepted | 3ms | 4888 KiB | ||||
115 | Accepted | 3ms | 4980 KiB | ||||
116 | Accepted | 3ms | 4936 KiB | ||||
117 | Accepted | 3ms | 4988 KiB | ||||
118 | Accepted | 3ms | 4992 KiB | ||||
119 | Accepted | 3ms | 4940 KiB | ||||
120 | Accepted | 3ms | 4948 KiB | ||||
121 | Accepted | 3ms | 5016 KiB | ||||
122 | Accepted | 3ms | 5272 KiB | ||||
123 | Accepted | 3ms | 5152 KiB | ||||
124 | Accepted | 59ms | 8368 KiB | ||||
125 | Accepted | 59ms | 8520 KiB | ||||
126 | Accepted | 61ms | 8488 KiB | ||||
127 | Accepted | 57ms | 8368 KiB | ||||
128 | Accepted | 63ms | 8372 KiB | ||||
129 | Accepted | 61ms | 8416 KiB | ||||
130 | Accepted | 59ms | 8452 KiB | ||||
131 | Accepted | 57ms | 8456 KiB | ||||
132 | Accepted | 59ms | 8460 KiB | ||||
133 | Accepted | 3ms | 3592 KiB | ||||
134 | Accepted | 3ms | 3596 KiB | ||||
135 | Accepted | 3ms | 4228 KiB | ||||
136 | Accepted | 3ms | 4136 KiB | ||||
137 | Accepted | 3ms | 4228 KiB | ||||
138 | Accepted | 3ms | 4144 KiB | ||||
139 | Accepted | 3ms | 3820 KiB | ||||
140 | Accepted | 3ms | 4020 KiB | ||||
141 | Accepted | 3ms | 4140 KiB | ||||
142 | Accepted | 3ms | 4136 KiB | ||||
143 | Accepted | 3ms | 4464 KiB | ||||
144 | Accepted | 52ms | 8148 KiB | ||||
145 | Accepted | 46ms | 7864 KiB | ||||
146 | Accepted | 54ms | 8304 KiB | ||||
147 | Accepted | 32ms | 7040 KiB | ||||
148 | Accepted | 54ms | 8260 KiB | ||||
149 | Accepted | 50ms | 8208 KiB | ||||
150 | Accepted | 3ms | 4560 KiB | ||||
151 | Accepted | 3ms | 4652 KiB | ||||
152 | Accepted | 50ms | 8096 KiB |