#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define all(x) begin(x),end(x)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;
#define dbg(...) fprintf(stderr,__VA_ARGS__)
const int N = 1e5+3;
int n, a[2*N];
ll p[2*N], S;
bool valid(ll l) {
int s = 1, e = 0;
ll sum = 0;
while (s <= n and e < n+s) {
if (sum < l) {
sum += a[++e];
} else {
int x = e+1, y = n+n, m;
while (x <= y) {
m = (x+y)/2;
if (p[m]-p[e] >= sum) y = m-1;
else x = m+1;
}
if (p[x]-p[e] > 0 and S-(p[x]-p[e])-sum >= sum) {
// dbg("%lld: [%d,%d]\n", sum,s,e);
// dbg("%lld: [%d,%d]\n", p[x]-p[e],e+1,x);
// dbg("%lld: [%d,%d]\n", S-(p[x]-p[e])-sum,x+1,s-1);
return true;
}
sum -= a[s++];
}
}
return false;
}
int main() {
scanf("%d", &n);
rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i];
S = p[n];
rep(i,n+1,n+n) p[i] = p[i-1]+a[i];
ll x = 0, y = 1e15, m;
while (x <= y) {
m = (x+y)/2;
if (valid(m)) x = m+1;
else y = m-1;
}
printf("%lld", y);
}
Compilation message
2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:44:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i];
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
488 KB |
Output is correct |
23 |
Correct |
5 ms |
468 KB |
Output is correct |
24 |
Correct |
7 ms |
492 KB |
Output is correct |
25 |
Correct |
6 ms |
468 KB |
Output is correct |
26 |
Correct |
11 ms |
468 KB |
Output is correct |
27 |
Correct |
7 ms |
468 KB |
Output is correct |
28 |
Correct |
9 ms |
500 KB |
Output is correct |
29 |
Correct |
10 ms |
468 KB |
Output is correct |
30 |
Correct |
12 ms |
492 KB |
Output is correct |
31 |
Correct |
5 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
468 KB |
Output is correct |
33 |
Correct |
5 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
35 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
7 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
488 KB |
Output is correct |
23 |
Correct |
5 ms |
468 KB |
Output is correct |
24 |
Correct |
7 ms |
492 KB |
Output is correct |
25 |
Correct |
6 ms |
468 KB |
Output is correct |
26 |
Correct |
11 ms |
468 KB |
Output is correct |
27 |
Correct |
7 ms |
468 KB |
Output is correct |
28 |
Correct |
9 ms |
500 KB |
Output is correct |
29 |
Correct |
10 ms |
468 KB |
Output is correct |
30 |
Correct |
12 ms |
492 KB |
Output is correct |
31 |
Correct |
5 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
468 KB |
Output is correct |
33 |
Correct |
5 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
35 |
Correct |
5 ms |
468 KB |
Output is correct |
36 |
Correct |
166 ms |
2628 KB |
Output is correct |
37 |
Correct |
183 ms |
2600 KB |
Output is correct |
38 |
Correct |
175 ms |
2644 KB |
Output is correct |
39 |
Correct |
157 ms |
2576 KB |
Output is correct |
40 |
Correct |
140 ms |
2644 KB |
Output is correct |
41 |
Correct |
135 ms |
2644 KB |
Output is correct |
42 |
Correct |
143 ms |
2624 KB |
Output is correct |
43 |
Correct |
187 ms |
2644 KB |
Output is correct |
44 |
Correct |
183 ms |
2696 KB |
Output is correct |
45 |
Correct |
142 ms |
2644 KB |
Output is correct |
46 |
Correct |
65 ms |
2544 KB |
Output is correct |
47 |
Correct |
73 ms |
2644 KB |
Output is correct |
48 |
Correct |
66 ms |
2536 KB |
Output is correct |