fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. #define FOR(i,a,b) for(int i=a; i<=b; i++)
  8. #define DOWN(i,a,b) for(int i=a; i>=b; i--)
  9.  
  10. typedef long long LL;
  11.  
  12.  
  13.  
  14. int main()
  15. {
  16. int n;
  17. LL MAX = -9999999999;
  18.  
  19. vector<LL> a,t3,T1,T2;
  20.  
  21. cin>>n;
  22.  
  23.  
  24. a.resize(n);
  25. FOR(i,0,n-1)
  26. cin>>a[i];
  27.  
  28. t3.resize(n);
  29. FOR(i,2,n-1)
  30. t3[i] = a[i] + a[i-1] + a[i-2];
  31.  
  32. T1.resize(n);
  33. T1[2] = t3[2];
  34. FOR(i,3,n-1)
  35. T1[i] = max(t3[i], T1[i-3] + t3[i]);
  36.  
  37. T2.resize(n);
  38. T2[n-3] = t3[n-1];// = a[n-3] + a[n-2] + a[n-1];
  39. DOWN(i,n-4,0)
  40. T2[i] = max(t3[i+2], T2[i+3] + t3[i+2]);
  41.  
  42. FOR(i,2,n-2)
  43. {
  44. FOR(j,i+1,n-3)
  45. {
  46. if( i < j && T1[i] + T2[j] > MAX)
  47. {
  48. MAX = T1[i] + T2[j];
  49. //cout<<i<<" - "<<j<<" : "<<MAX<<endl;
  50. }
  51. //MAX = max(MAX,T1[i] + T2[j]);
  52. }
  53. }
  54.  
  55. cout<<MAX<<endl;
  56.  
  57. return 0;
  58. }
Runtime error #stdin #stdout #stderr 0s 3460KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::length_error'
  what():  vector::_M_fill_insert