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 suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
ll n;
ll arr[1000001];
ll precal[1000001];
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>arr[i];
for(int i=1;i<=n/2;i++) precal[1]+=arr[i];
ll last=n/2+1;
for(int i=2,j=n/2+1;max(i,j)<=n;i++,j++){
precal[i]=precal[i-1]+arr[j]-arr[i-1];
last=i;
}
for(int j=1,i=last+1;max(i,j)<=n;i++,j++) precal[i]=precal[i-1]+arr[j]-arr[i-1];
ll sum=0,mx=-1;
for(int i=1;i<=n;i++){
// co precal[i]<<' ';
sum+=arr[i];
}
// co '\n';
sort(precal+1,precal+1+n);
reverse(precal+1,precal+1+n);
if(n==2){
co sum-precal[2];
}
else{
co sum-precal[3];
}
}
int main()
{
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
return 0;
}
Compilation message (stderr)
hac.cpp: In function 'void solve()':
hac.cpp:23:14: warning: unused variable 'mx' [-Wunused-variable]
23 | ll sum=0,mx=-1;
| ^~
# | 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... |