10783 | 2024-04-12 15:49:58 | 111 | Metróutasok | cpp17 | Accepted 100/100 | 68ms | 7604 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef CB
freopen("be1.txt","r",stdin);
// freopen("ki.txt","w",stdout);
#endif
int N;
cin>>N;
vector<int>v(N+1),p(N+1);
for(int i=1;i<=N;i++){
cin>>v[i];
p[i]=p[i-1]+v[i];
}
int l=v[1],h=p[N];
while(l<h){
int m=(l+h)/2;
int ok=1;
int mn=0;
for(int i=1;i<=N;i++){
mn=max(mn,(v[i]+1)/2);
}
int x=0;
int a=0;
for(int i=1;i<=N;i++){
int y=min(x,m-(m%2!=x%2));
a=min(abs(a-v[i]),abs(y-v[i]));
x+=v[i];
if(y>=v[i]){
a=min(a,x&1);
}
mn=max(mn,a);
}
x=0;
a=0;
for(int i=N;i>=1;i--){
int y=min(x,m-(m%2!=x%2));
a=min(abs(a-v[i]),abs(y-v[i]));
x+=v[i];
if(y>=v[i]){
a=min(a,x&1);
}
mn=max(mn,a);
}
ok&=mn<=m;
if(ok){
h=m;
}
else{
l=m+1;
}
}
cout<<h<<'\n';
l=v[1],h=p[N];
while(l<h){
int m=(l+h)/2;
int ok=0;
for(int i=1;i<=N;i++){
if(p[i]>=m&&p[N]-p[i]>=m){
ok=1;
}
}
if(ok){
l=m+1;
}
else{
h=m;
}
}
cout<<l-1<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1700 KiB | ||||
2 | Accepted | 67ms | 4888 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2076 KiB | ||||
4 | Accepted | 3ms | 2284 KiB | ||||
5 | Accepted | 3ms | 2504 KiB | ||||
6 | Accepted | 3ms | 2708 KiB | ||||
7 | Accepted | 3ms | 2928 KiB | ||||
8 | Accepted | 3ms | 3136 KiB | ||||
9 | Accepted | 3ms | 3224 KiB | ||||
10 | Accepted | 2ms | 3364 KiB | ||||
11 | Accepted | 3ms | 3456 KiB | ||||
12 | Accepted | 3ms | 3684 KiB | ||||
13 | Accepted | 3ms | 3732 KiB | ||||
14 | Accepted | 3ms | 3728 KiB | ||||
15 | Accepted | 2ms | 3840 KiB | ||||
16 | Accepted | 3ms | 3824 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 3ms | 2076 KiB | ||||
18 | Accepted | 3ms | 2284 KiB | ||||
19 | Accepted | 3ms | 2504 KiB | ||||
20 | Accepted | 3ms | 2708 KiB | ||||
21 | Accepted | 3ms | 2928 KiB | ||||
22 | Accepted | 3ms | 3136 KiB | ||||
23 | Accepted | 3ms | 3224 KiB | ||||
24 | Accepted | 2ms | 3364 KiB | ||||
25 | Accepted | 3ms | 3456 KiB | ||||
26 | Accepted | 3ms | 3684 KiB | ||||
27 | Accepted | 3ms | 3728 KiB | ||||
28 | Accepted | 3ms | 3628 KiB | ||||
29 | Accepted | 2ms | 3624 KiB | ||||
30 | Accepted | 3ms | 3620 KiB | ||||
31 | Accepted | 3ms | 3748 KiB | ||||
32 | Accepted | 3ms | 3828 KiB | ||||
33 | Accepted | 3ms | 3836 KiB | ||||
34 | Accepted | 3ms | 3988 KiB | ||||
35 | Accepted | 3ms | 4056 KiB | ||||
36 | Accepted | 3ms | 3836 KiB | ||||
37 | Accepted | 3ms | 3732 KiB | ||||
38 | Accepted | 3ms | 3728 KiB | ||||
39 | Accepted | 2ms | 3836 KiB | ||||
40 | Accepted | 3ms | 3936 KiB | ||||
41 | Accepted | 3ms | 4164 KiB | ||||
42 | Accepted | 3ms | 4272 KiB | ||||
43 | Accepted | 2ms | 3840 KiB | ||||
44 | Accepted | 3ms | 3824 KiB | ||||
45 | Accepted | 3ms | 4164 KiB | ||||
46 | Accepted | 3ms | 4292 KiB | ||||
47 | Accepted | 3ms | 4280 KiB | ||||
48 | Accepted | 2ms | 4384 KiB | ||||
49 | Accepted | 3ms | 4280 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 3ms | 2076 KiB | ||||
51 | Accepted | 3ms | 2284 KiB | ||||
52 | Accepted | 3ms | 2504 KiB | ||||
53 | Accepted | 3ms | 2708 KiB | ||||
54 | Accepted | 3ms | 2928 KiB | ||||
55 | Accepted | 3ms | 3136 KiB | ||||
56 | Accepted | 3ms | 3224 KiB | ||||
57 | Accepted | 2ms | 3364 KiB | ||||
58 | Accepted | 3ms | 3456 KiB | ||||
59 | Accepted | 3ms | 3684 KiB | ||||
60 | Accepted | 3ms | 3728 KiB | ||||
61 | Accepted | 3ms | 3628 KiB | ||||
62 | Accepted | 2ms | 3624 KiB | ||||
63 | Accepted | 3ms | 3620 KiB | ||||
64 | Accepted | 3ms | 3748 KiB | ||||
65 | Accepted | 3ms | 3828 KiB | ||||
66 | Accepted | 3ms | 3836 KiB | ||||
67 | Accepted | 3ms | 3988 KiB | ||||
68 | Accepted | 3ms | 4056 KiB | ||||
69 | Accepted | 3ms | 3836 KiB | ||||
70 | Accepted | 3ms | 4264 KiB | ||||
71 | Accepted | 3ms | 4264 KiB | ||||
72 | Accepted | 3ms | 4508 KiB | ||||
73 | Accepted | 3ms | 4260 KiB | ||||
74 | Accepted | 3ms | 4364 KiB | ||||
75 | Accepted | 2ms | 4268 KiB | ||||
76 | Accepted | 3ms | 4260 KiB | ||||
77 | Accepted | 3ms | 4264 KiB | ||||
78 | Accepted | 3ms | 4264 KiB | ||||
79 | Accepted | 3ms | 4268 KiB | ||||
80 | Accepted | 3ms | 3732 KiB | ||||
81 | Accepted | 3ms | 3728 KiB | ||||
82 | Accepted | 2ms | 3836 KiB | ||||
83 | Accepted | 3ms | 3936 KiB | ||||
84 | Accepted | 3ms | 4164 KiB | ||||
85 | Accepted | 3ms | 4272 KiB | ||||
86 | Accepted | 2ms | 3840 KiB | ||||
87 | Accepted | 3ms | 3824 KiB | ||||
88 | Accepted | 3ms | 4164 KiB | ||||
89 | Accepted | 3ms | 4292 KiB | ||||
90 | Accepted | 3ms | 4280 KiB | ||||
91 | Accepted | 2ms | 4384 KiB | ||||
92 | Accepted | 3ms | 4280 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 3ms | 2076 KiB | ||||
94 | Accepted | 67ms | 7160 KiB | ||||
95 | Accepted | 3ms | 2284 KiB | ||||
96 | Accepted | 3ms | 2504 KiB | ||||
97 | Accepted | 3ms | 2708 KiB | ||||
98 | Accepted | 3ms | 2928 KiB | ||||
99 | Accepted | 3ms | 3136 KiB | ||||
100 | Accepted | 3ms | 3224 KiB | ||||
101 | Accepted | 2ms | 3364 KiB | ||||
102 | Accepted | 3ms | 3456 KiB | ||||
103 | Accepted | 3ms | 3684 KiB | ||||
104 | Accepted | 3ms | 3728 KiB | ||||
105 | Accepted | 3ms | 3628 KiB | ||||
106 | Accepted | 2ms | 3624 KiB | ||||
107 | Accepted | 3ms | 3620 KiB | ||||
108 | Accepted | 3ms | 3748 KiB | ||||
109 | Accepted | 3ms | 3828 KiB | ||||
110 | Accepted | 3ms | 3836 KiB | ||||
111 | Accepted | 3ms | 3988 KiB | ||||
112 | Accepted | 3ms | 4056 KiB | ||||
113 | Accepted | 3ms | 3836 KiB | ||||
114 | Accepted | 3ms | 4264 KiB | ||||
115 | Accepted | 3ms | 4264 KiB | ||||
116 | Accepted | 3ms | 4508 KiB | ||||
117 | Accepted | 3ms | 4260 KiB | ||||
118 | Accepted | 3ms | 4364 KiB | ||||
119 | Accepted | 2ms | 4268 KiB | ||||
120 | Accepted | 3ms | 4260 KiB | ||||
121 | Accepted | 3ms | 4264 KiB | ||||
122 | Accepted | 3ms | 4264 KiB | ||||
123 | Accepted | 3ms | 4268 KiB | ||||
124 | Accepted | 68ms | 7164 KiB | ||||
125 | Accepted | 68ms | 7208 KiB | ||||
126 | Accepted | 68ms | 7160 KiB | ||||
127 | Accepted | 67ms | 7216 KiB | ||||
128 | Accepted | 67ms | 7212 KiB | ||||
129 | Accepted | 67ms | 7160 KiB | ||||
130 | Accepted | 67ms | 7164 KiB | ||||
131 | Accepted | 65ms | 7160 KiB | ||||
132 | Accepted | 65ms | 7308 KiB | ||||
133 | Accepted | 3ms | 3732 KiB | ||||
134 | Accepted | 3ms | 3728 KiB | ||||
135 | Accepted | 2ms | 3836 KiB | ||||
136 | Accepted | 3ms | 3936 KiB | ||||
137 | Accepted | 3ms | 4164 KiB | ||||
138 | Accepted | 3ms | 4272 KiB | ||||
139 | Accepted | 2ms | 3840 KiB | ||||
140 | Accepted | 3ms | 3824 KiB | ||||
141 | Accepted | 3ms | 4164 KiB | ||||
142 | Accepted | 3ms | 4292 KiB | ||||
143 | Accepted | 3ms | 4280 KiB | ||||
144 | Accepted | 45ms | 7032 KiB | ||||
145 | Accepted | 41ms | 6644 KiB | ||||
146 | Accepted | 46ms | 7196 KiB | ||||
147 | Accepted | 28ms | 5992 KiB | ||||
148 | Accepted | 43ms | 7388 KiB | ||||
149 | Accepted | 43ms | 7604 KiB | ||||
150 | Accepted | 2ms | 4384 KiB | ||||
151 | Accepted | 3ms | 4280 KiB | ||||
152 | Accepted | 41ms | 7444 KiB |