Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<cstdio>
  2. #include<cstring>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11.     int dia;
  12.     int soma;
  13.     int maximo;
  14.     int n;
  15.     while(scanf("%d",&n)!=EOF)
  16.     {
  17.         if(n==0)
  18.         {
  19.             break;
  20.         }
  21.         maximo=-101;
  22.         soma=0;
  23.         for(int i=0; i<n; i++)
  24.         {
  25.             scanf("%d",&dia);
  26.             soma+=dia;
  27.             if(soma>maximo)
  28.             {
  29.                 maximo=soma;
  30.             }
  31.             if(soma<0)
  32.             {
  33.                 soma=0;
  34.             }
  35.         }
  36.         printf("%d\n", maximo);
  37.     }
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement