fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. #define FOR(i,a,b) for(int i=a; i<b; i++)
  8. #define LL long long
  9.  
  10.  
  11. int main()
  12. {
  13. int n;
  14. vector<LL> T;
  15. LL a;
  16.  
  17. cin>>n;
  18. T.resize(n+1);
  19.  
  20. FOR(i,1,n+1)
  21. {
  22. cin>>a;
  23. T[i] = T[i-1] + a;
  24. }
  25.  
  26. LL MAX = -9999999999;
  27.  
  28. FOR(i,1,n+1)
  29. {
  30. FOR(j,i,n+1)
  31. {
  32. if((j-i+1)%3 == 0)
  33. {
  34. LL t = T[j] - T[i-1];
  35. MAX = max(t,MAX);
  36. }
  37. }
  38. }
  39.  
  40. cout<<MAX<<endl;
  41.  
  42. return 0;
  43. }
Runtime error #stdin #stdout #stderr 0s 4484KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc