#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+n) {
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) {
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:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:41:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | 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 |
2484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
5 ms |
604 KB |
Output is correct |
24 |
Correct |
6 ms |
604 KB |
Output is correct |
25 |
Correct |
6 ms |
2648 KB |
Output is correct |
26 |
Correct |
10 ms |
2652 KB |
Output is correct |
27 |
Correct |
7 ms |
604 KB |
Output is correct |
28 |
Correct |
8 ms |
708 KB |
Output is correct |
29 |
Correct |
8 ms |
604 KB |
Output is correct |
30 |
Correct |
11 ms |
608 KB |
Output is correct |
31 |
Correct |
5 ms |
604 KB |
Output is correct |
32 |
Correct |
5 ms |
604 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
5 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2484 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
6 ms |
604 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
5 ms |
604 KB |
Output is correct |
24 |
Correct |
6 ms |
604 KB |
Output is correct |
25 |
Correct |
6 ms |
2648 KB |
Output is correct |
26 |
Correct |
10 ms |
2652 KB |
Output is correct |
27 |
Correct |
7 ms |
604 KB |
Output is correct |
28 |
Correct |
8 ms |
708 KB |
Output is correct |
29 |
Correct |
8 ms |
604 KB |
Output is correct |
30 |
Correct |
11 ms |
608 KB |
Output is correct |
31 |
Correct |
5 ms |
604 KB |
Output is correct |
32 |
Correct |
5 ms |
604 KB |
Output is correct |
33 |
Correct |
5 ms |
604 KB |
Output is correct |
34 |
Correct |
5 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
604 KB |
Output is correct |
36 |
Correct |
158 ms |
3728 KB |
Output is correct |
37 |
Correct |
167 ms |
3676 KB |
Output is correct |
38 |
Correct |
164 ms |
3676 KB |
Output is correct |
39 |
Correct |
151 ms |
3672 KB |
Output is correct |
40 |
Correct |
128 ms |
3672 KB |
Output is correct |
41 |
Correct |
125 ms |
3728 KB |
Output is correct |
42 |
Correct |
128 ms |
3672 KB |
Output is correct |
43 |
Correct |
187 ms |
3676 KB |
Output is correct |
44 |
Correct |
171 ms |
3724 KB |
Output is correct |
45 |
Correct |
130 ms |
3728 KB |
Output is correct |
46 |
Correct |
65 ms |
2908 KB |
Output is correct |
47 |
Correct |
72 ms |
2904 KB |
Output is correct |
48 |
Correct |
65 ms |
2952 KB |
Output is correct |