Advertisement
Josif_tepe

Untitled

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