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>
using namespace std;
using ll = long long;
ll N;
ll A[100005];
ll S[100005];
int main(){
cin.tie(0) -> sync_with_stdio(false);
cin >> N;
for(int i = 1; i <= N; i++){
cin >> A[i];
A[i + N] = A[i];
}
for(int i = 1; i <= 2 * N; i++){
S[i] = S[i - 1] + A[i];
}
ll L = 1, R = 1, ans = 0;
while(L <= R && L <= N && R <= 2 * N && R - L + 1 <= N){
ll V = S[R] - S[L - 1];
ll idx = upper_bound(S + R + 1, S + L + N, S[R] + V) - S;
if(S[L + N - 1] - S[idx] >= V){
ans = max(ans, V);
R++;
} else {
L++;
}
}
cout << ans;
}
# | 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... |