이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vi a(2 * n + 1);
a[0] = 0;
multiset<int> vals;
int SZ = (n + 1) / 2;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[n + i] = a[i];
}
for (int i = 1; i <= 2 * n; i++) {
a[i] += a[i - 1];
}
int ans = 0;
vi ret(n + 1, INT_MAX);
for (int i = 1; i <= 2 * n; i++) {
cerr << "i: " << i << '\n';
if (i + SZ - 1 <= 2 * n) {
vals.insert(a[i + SZ - 1] - a[i - 1]);
cerr << "adding: " << i << " " << i + SZ - 1 << '\n';
}
if (i > SZ) {
vals.erase(vals.find(a[i - 1] - a[i - 1 - SZ]));
cerr << "removing: " << i - SZ << " " << i - 1 << '\n';
}
cerr << "vals: " << '\n';
/*
for (int x : vals) {
cerr << x << " ";
}
*/
cerr << '\n';
int prev = ((i - 1) % n) + 1;
// cout << "i, prev: " << i << " " << prev << '\n';
ret[prev] = min(ret[prev], *vals.begin());
}
for (int i = 1; i <= n; i++) {
cerr << i << " " << ret[i] << '\n';
ans = max(ans, ret[i]);
}
cout << ans << '\n';
}
# | 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... |