fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long int zysk=0,temp,suma=0;
  8. int t,x=0,y=1,tab[100000];
  9.  
  10. cin>>t;
  11.  
  12. for(int a=1; a<=t; a++)
  13. {
  14. cin>>tab[a-1];
  15. suma+=a;
  16. }
  17.  
  18. for(int a=0; a<suma; a++)
  19. {
  20. temp=0;
  21.  
  22. for(int b=x; b<y; b++)
  23. {
  24. temp+=tab[b];
  25. }
  26.  
  27. if(temp>zysk)
  28. zysk=temp;
  29.  
  30. if(y==t)
  31. {
  32. y=x+1;
  33. x++;
  34. }
  35.  
  36. y++;
  37. }
  38. cout<<zysk<<endl;
  39. }
  40.  
Success #stdin #stdout 0s 4532KB
stdin
5
1
-2
4
5
-2
stdout
9