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>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
//find maximum of minimum (n+1)/2
int n;
cin>>n;
vector<int> nums(n);
vector<int> p(n+1);
int maxi=0;
for (int i=0;i<n;i++){
cin>>nums[i];
}
for (int i=1;i<n+1;i++){
p[i]=nums[i-1]+p[i-1];
}
for (int i=0;i<n;i++){
int cur1=0;
if(i+(n+1)/2>n){
// cout<<"e"<<i<<"\n";
// cout<<p[n]-p[i]<<"\n";
cur1+=p[n]-p[i];
cur1+=p[((i+(n+1)/2)%n)]-p[0];
} else {
cur1+=p[i+(n+1)/2]-p[i];
}
int cur2=0;
if(i+1-(n+1)/2<0){
cur2+=p[i+1]-p[0];
// cout<<"e"<<abs(i+1-(n+1)/2)+1<<"\n";
cur2+=p[n]-p[n-abs(i+1-(n+1)/2)];
} else {
// cout<<"e"<<i<<"\n";
cur2+=p[i+1]-p[i+1-(n+1)/2];
}
// cout<<cur1<<"\n";
// cout<<cur2<<"\n";
maxi=max(maxi,min(cur1,cur2));
}
cout<<maxi<<"\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... |