Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- long long niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- long long sum = niza[0];
- long long result = niza[0];
- for(int i = 1; i < n; i++) {
- if(sum + niza[i] > niza[i]) {
- sum += niza[i];
- }
- else {
- sum = niza[i];
- }
- if(result < sum) {
- result = sum;
- }
- }
- cout << result << endl;
- return 0;
- }
- /*
- 2
- -3 -2
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement