Advertisement
Graf_Rav

87 Zhukov

May 22nd, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n;
  7.     cin>>n;
  8.    
  9.     int a;
  10.     cin>>a;
  11.     int sum=a;
  12.    
  13.     int ans=-0x80000000;
  14.     if(sum>ans){
  15.         ans=sum;
  16.     }
  17.    
  18.     for(int i=1;i<n;i++){
  19.         cin>>a;
  20.         if(a>ans){
  21.             ans=a;
  22.         }
  23.        
  24.         if(sum<0){
  25.             sum=a;
  26.         }
  27.         else{
  28.             sum+=a;
  29.         }
  30.        
  31.         if(sum>ans){
  32.             ans=sum;
  33.         }
  34.     }
  35.     cout<<ans;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement