Source Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <iomanip>
#include <fstream>
#include <chrono>

using namespace std;

int main()
{
    int n, l = 0, r;
    long long int z = 0;
    cin >> n;
    r = n - 1;
    int movies[1000000];
    long long int sum[1000000];

        cin >> movies[0];
        sum[0] = movies[0];
    for (int i = 1; i < n; i++)
    {
        cin >> movies[i];
        sum[i] = sum[i - 1] + movies[i];
    }
    int max = sum[r];

    while (r != l)
    {
        if (movies[r] < movies[l])
        {
            r--;
        }
        else
        {
            z += movies[l];
            l++;
        }

        if (sum[r] - z > max)
        {
            max = sum[r] - z;
        }
    }

    if (movies[r] > max)
    {
        max = movies[r];
    }

    cout << max << endl;

    return 0;
}
Copy
Movies DirtyQWERTY
GNU G++17
197 ms
12.2 MB
Wrong Answer