Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. /*
  2. ID: hepic
  3. PROG: ariprog
  4. LANG: C++11
  5. */
  6. #include<bits/stdc++.h>
  7.  
  8. #define FOR(i,a,b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
  9. #define REP(i,a,b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
  10. #define ALL(v) v.begin(),v.end()
  11. #define what_is(x) cout<<#x<<" is "<<x<<endl;
  12. #define min3(a,b,c) min(min(a,b),c)
  13. #define SIZE 1000010
  14. #define MAXN 1000000010
  15. #define PI 3.141592653589793
  16. #define open_read1 freopen("C:\\Users\\Hepic\\Desktop\\a.txt","r",stdin)
  17. #define open_read freopen("ariprog.in","r",stdin)
  18. #define open_write freopen("ariprog.out","w",stdout)
  19.  
  20. using namespace std;
  21.  
  22.  
  23. typedef long long LL;
  24. typedef pair<int,int> PII;
  25.  
  26. LL N;
  27. LL payment[SIZE];
  28. LL dp_val[SIZE];
  29. LL ptrA,ptrB;
  30. LL sumA,sumB,sumC;
  31. LL NsumA,NsumC;
  32. LL min_of_max_sum=-1;
  33.  
  34.  
  35. int main()
  36. {
  37. open_read1;
  38. scanf("%lld",&N);
  39.  
  40. scanf("%lld",&payment[0]);
  41. dp_val[0]=payment[0];
  42. for(int i=1; i<N; ++i)
  43. {
  44. scanf("%lld",&payment[i]);
  45. dp_val[i]=dp_val[i-1]+payment[i];
  46. }
  47.  
  48.  
  49. ptrA=N/3;
  50. ptrB=(2*N)/3;
  51.  
  52.  
  53. for(int times=1; times<=N; ++times)
  54. {
  55. sumA=dp_val[ptrA];
  56. sumB=dp_val[ptrB]-dp_val[ptrA];
  57. sumC=dp_val[N-1]-dp_val[ptrB];
  58.  
  59.  
  60. if(sumA>max(sumB,sumC))
  61. {
  62. if(min_of_max_sum==-1 || sumA<min_of_max_sum)
  63. min_of_max_sum=sumA;
  64.  
  65. --ptrA;
  66. }
  67.  
  68. else if(sumB>max(sumA,sumC))
  69. {
  70. if(min_of_max_sum==-1 || sumB<min_of_max_sum)
  71. min_of_max_sum=sumB;
  72.  
  73.  
  74. NsumA=dp_val[ptrA+1];
  75. NsumC=dp_val[N-1]-dp_val[ptrB-1];
  76.  
  77. if(NsumC<=NsumA)
  78. --ptrB;
  79. else
  80. ++ptrA;
  81.  
  82. }
  83.  
  84. else if(sumC>max(sumA,sumB))
  85. {
  86. if(min_of_max_sum==-1 || sumC<min_of_max_sum)
  87. min_of_max_sum=sumC;
  88.  
  89. ++ptrB;
  90. }
  91. }
  92.  
  93. printf("%lld",min_of_max_sum);
  94.  
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement