#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 3e5 + 10;
int n,a[N];
namespace sub1
{
bool check()
{
return (n<=5000);
}
const int N = 5e3 + 10;
int b[N];
void solve()
{
for(int tri=1;tri<=n;++tri)
{
ll s[2]; s[0]=s[1]=0;
s[0]+=a[tri];
int ptr=0,pos=tri+1;
while(1)
{
if(pos==n+1) pos=1;
if(pos==tri) break;
b[++ptr]=a[pos];
++pos;
}
int l=1,r=ptr;
bool state=0;
while(1)
{
if(l>r) break;
state^=1;
if(b[l]>=b[r])
{
s[state]+=b[l];
++l;
}
else
{
s[state]+=b[r];
--r;
}
}
cout<<s[0]<<'\n';
}
}
}
void solve()
{
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i];
if(sub1::check()) return void(sub1::solve());
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
int testcase=1;
// cin>>testcase;
while (testcase--)
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |