이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 500005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,a[maxn << 1];
long long ans,sum[maxn << 1];
long long Get(int l,int r)
{
l %= n;
r %= n;
if (l <= r)
{
if (l) return sum[r] - sum[l-1];
return sum[r];
}
else
{
return sum[r] + sum[n-1] - sum[l-1];
}
}
int main()
{
ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
//freopen(Task".inp", "r",stdin);
//freopen(Task".out", "w",stdout);
read(n);
FOR(i,0,n-1)
{
read(a[i]);
a[i+n] = a[i];
}
sum[0] = a[0];
FOR(i,1,2*n-1) sum[i] = sum[i-1] + a[i];
FOR(i,0,n-1)
{
long long cur = 0;
FOR(j,i+n/2,i+n-1)
{
cur = max(cur,Get(j-n/2+1,j));
}
ans = max(ans,sum[n-1] - cur);
}
cout << ans;
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... |