CSES - Shared codeLink to this code: https://cses.fi/paste/5900cd60d6a09ffc6b47b9/
#include<bits/stdc++.h>
#define int long long
#define ff first
#define ss second
using namespace std;
void solve()
{
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int run = a[0],ans = -1e10;
    for (int i = 1; i < n; i++)
    {
        run = max(run+a[i],a[i]);
        ans = max(ans,run);
    }
    ans = max(ans,run);
    cout << ans << endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
        solve();
    
}