#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[N];
ll p[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 {
ll 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 (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];
S = p[n];
rep(i,n+1,n+n) p[i] = p[i-1]+a[i-n];
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:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:39:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i];
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |