Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
382 B
1
Indexable
Never
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  cin >> n;

  int niza[n];
  for(int i = 0; i < n; i++) {
    cin >> niza[i];
  }
  long long res = -1e18;
  for(int i = 0; i < n; i++) {
    long long sum = 0;
    for(int j = i; j < n; j++) {
        sum += niza[j];
        res = max(sum, res);
    }
  }
  cout << res << endl;

  return 0;
}
 
Leave a Comment