# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1097134 | hgmhc | 도넛 (JOI14_ho_t3) | C++17 | 171 ms | 2760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
using namespace std; using ll = long long;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |