Source Code


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

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

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

sum = sum + arr[i];

if (sum < 0) sum = 0;

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



}

cout << maxSoFar;

    return 0;
}
Copy
Movies microwave6
GNU G++17
269 ms
4.1 MB
Wrong Answer