이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 500'010;
int seg[2*N];
const int inf = 1e9+10;
void up(int l, int r, int x)
{
l += N;
r += N;
while (l < r) {
if (l&1) {
seg[l] = min(seg[l], x);
++l;
}
if (r&1) {
--r;
seg[r] = min(seg[r], x);
}
l /= 2;
r /= 2;
}
}
int get(int i)
{
i += N;
int ans = inf;
while (i) {
ans = min(ans, seg[i]);
i /= 2;
}
return ans;
}
int n;
int a[N];
int pre[N];
int main()
{
cin.tie(0) -> sync_with_stdio(false);
fill(seg, seg+2*N, inf);
cin >> n;
Loop (i,0,n) {
cin >> a[i];
pre[i+1] = pre[i] + a[i];
}
int len = (n+1)/2;
Loop (i,0,n) {
if (i+len <= n) {
int sum = pre[i+len] - pre[i];
up(i, i+len, sum);
} else {
int sum = pre[n] - pre[i] + pre[i+len-n];
up(i, n, sum);
up(0, i+len-n, sum);
}
}
int ans = 0;
Loop (i,0,n)
ans = max(ans, get(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... |