Source Code


#include <iostream>
#include <limits.h>
using namespace std;
int main()
{
    // 5 -2 1000
    long long n, arr[1000000];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> arr[i] ;
    }

long long sum = arr[0];
long long maxSoFar = INT_MIN;

for(int i=1; i<n; i++){

sum = sum + arr[i];



if (sum > maxSoFar) {
    maxSoFar = sum;
}


if (sum < 0) sum = 0;
}

cout << maxSoFar;

    return 0;
}
Copy
Movies microwave6
GNU G++17
393 ms
8.6 MB
Wrong Answer