Source Code
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <limits.h>
using namespace std;
int main()
{
    // 5 -2 1000
    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 > maxSoFar) {
    maxSoFar = sum;
}


if (sum < 0) sum = 0;
}

cout << maxSoFar;

    return 0;
}
Copy
Movies microwave6
GNU G++17
307 ms
4.7 MB
Wrong Answer