Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: hepic
- PROG: ariprog
- LANG: C++11
- */
- #include<bits/stdc++.h>
- #define FOR(i,a,b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
- #define REP(i,a,b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
- #define ALL(v) v.begin(),v.end()
- #define what_is(x) cout<<#x<<" is "<<x<<endl;
- #define min3(a,b,c) min(min(a,b),c)
- #define SIZE 1000010
- #define MAXN 1000000010
- #define PI 3.141592653589793
- #define open_read1 freopen("C:\\Users\\Hepic\\Desktop\\a.txt","r",stdin)
- #define open_read freopen("ariprog.in","r",stdin)
- #define open_write freopen("ariprog.out","w",stdout)
- using namespace std;
- typedef long long LL;
- typedef pair<int,int> PII;
- LL N;
- LL payment[SIZE];
- LL dp_val[SIZE];
- LL ptrA,ptrB;
- LL sumA,sumB,sumC;
- LL NsumA,NsumC;
- LL min_of_max_sum=-1;
- int main()
- {
- open_read1;
- scanf("%lld",&N);
- scanf("%lld",&payment[0]);
- dp_val[0]=payment[0];
- for(int i=1; i<N; ++i)
- {
- scanf("%lld",&payment[i]);
- dp_val[i]=dp_val[i-1]+payment[i];
- }
- ptrA=N/3;
- ptrB=(2*N)/3;
- for(int times=1; times<=N; ++times)
- {
- sumA=dp_val[ptrA];
- sumB=dp_val[ptrB]-dp_val[ptrA];
- sumC=dp_val[N-1]-dp_val[ptrB];
- if(sumA>max(sumB,sumC))
- {
- if(min_of_max_sum==-1 || sumA<min_of_max_sum)
- min_of_max_sum=sumA;
- --ptrA;
- }
- else if(sumB>max(sumA,sumC))
- {
- if(min_of_max_sum==-1 || sumB<min_of_max_sum)
- min_of_max_sum=sumB;
- NsumA=dp_val[ptrA+1];
- NsumC=dp_val[N-1]-dp_val[ptrB-1];
- if(NsumC<=NsumA)
- --ptrB;
- else
- ++ptrA;
- }
- else if(sumC>max(sumA,sumB))
- {
- if(min_of_max_sum==-1 || sumC<min_of_max_sum)
- min_of_max_sum=sumC;
- ++ptrB;
- }
- }
- printf("%lld",min_of_max_sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement