Advertisement
Emiliatan

b565

Apr 6th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. /* b565           */
  2. /* AC (0ms, 92KB) */
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. int arr[50];
  8. int n, Max, sum;
  9.  
  10. int main()
  11. {
  12.     for(~scanf("%d", &n))
  13.     {
  14.         for(int i = 0; i < n && scanf("%d", &sum); arr[i] = sum, i++);
  15.  
  16.         Max = sum = 0;
  17.         for(int i = 0; i < n; i++)
  18.         {
  19.             sum += arr[i];
  20.             if(sum < 0) sum = 0;
  21.             Max = (sum > Max ? sum : Max);
  22.         }
  23.  
  24.         printf("%d\n", Max);
  25.     }
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement