Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created November 5, 2019 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/f023e6135108c6ae60be03c7e66a885b to your computer and use it in GitHub Desktop.
Save pinglunliao/f023e6135108c6ae60be03c7e66a885b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int seq[n];
for(int i = 0; i < n; i++)
cin >> seq[i];
int best_sum = INT_MIN;
int current_sum = 0;
for(int i = 0; i < n; i++)
{
current_sum = max(0, (current_sum + seq[i]));
best_sum = max(best_sum, current_sum);
}
cout << best_sum << " " << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment