Advertisement
Josif_tepe

Untitled

Jun 16th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. cin>>n;
  10. int niza[n];
  11. for(int i=0; i<n; i++){
  12.     cin>>niza[i];
  13. }
  14. long long sum=0;
  15. long long nsum=-1e18;
  16.  
  17. for(int j=0; j<n; j++){
  18.     if(sum+niza[j]>=niza[j]){
  19.         sum+=niza[j];
  20.     }
  21.     else{
  22.         sum=niza[j];
  23.     }
  24.     if(sum>nsum){
  25.         nsum=sum;
  26.     }
  27. }
  28.     cout<<nsum;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement