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 <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#define int long long
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n;
m = (n+1)/2;
vector<int>a(3*n+1), s(3*n+1);
for(int i = 1; i <= n; i ++){
cin >> a[i];
a[i+n] = a[i+2*n] = a[i];
}
multiset<int> ms;
for(int i = 1; i < m; i ++)
s[i] = s[i-1] + a[i];
for(int i = m; i < 2*m; i ++){
s[i] = s[i-1] - a[i-m] + a[i];
ms.insert(s[i]);
}
int res = *ms.begin();
for(int i = m; i < n + m; i ++){
ms.erase(ms.find(s[i]));
s[i+m] = s[i+m-1] - a[i] + a[i+m];
ms.insert(s[i+m]);
res = max(res, *ms.begin());
}
cout << res;
return 0;
}
# | 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... |