Josif_tepe

Untitled

Jul 18th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main(){
  5.    ll n;
  6.    cin>>n;
  7.    ll arr[n];
  8.    ll sum=0, maxsum=-100000000;
  9.    ll rez=-10000000;
  10.    for(int i=0; i<n;i++){
  11.        cin>>arr[i];
  12.    }
  13.    for(int i=0;i<n;i++){
  14.        sum+=arr[i];
  15.        maxsum=max(maxsum+arr[i], arr[i]);
  16.     if(maxsum>rez){
  17.         rez=maxsum;
  18.     }
  19.    }
  20.    cout<<rez;
  21.    
  22.    
  23.    
  24.  return 0;
  25. }
Add Comment
Please, Sign In to add comment