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 all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n;
cin >> n;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
for(int i=1; i<=n; i++) v.push_back(v[i]);
vector<ll> pref(2*n+1);
for(int i=1; i<=2*n; i++) pref[i] = pref[i-1] + v[i];
vector<ll> ans(n+1, 1e18);
int len = (n + 1) / 2;
for(int i=1; i<=n; i++) {
ll val = pref[i+len-1] - pref[i-1];
for(int j=i; j<=i+len-1; j++) {
if(j <= n) ans[j] = min(ans[j], val);
else ans[j-n] = min(ans[j-n], val);
}
}
cout << *max_element(ans.begin() + 1, ans.end()) << '\n';
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... |