chillurbrain

5. Гиперпереход

May 22nd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. int a[70000];
  5. int myMax(int x, int y)
  6. {
  7.     if(x>y)
  8.         return x;
  9.     return y;
  10. }
  11. int main()
  12. {
  13.     int n;
  14.     cin>>n;
  15.     for(int i=1;i<=n;++i)
  16.         cin>>a[i];
  17.     int sum=0;
  18.     int ans=0;
  19.     for(int i=1;i<=n;++i)
  20.     {
  21.         sum=myMax(0,sum+a[i]);
  22.         ans=myMax(sum,ans);
  23.     }
  24.     cout<<ans;
  25.     return 0;
  26. }
Add Comment
Please, Sign In to add comment