Submission #971680

#TimeUsernameProblemLanguageResultExecution timeMemory
971680LucaIlieCigle (COI21_cigle)C++17
0 / 100
3 ms2904 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5000;
int d[MAX_N + 1], sd[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1];

int main() {
    int n;

    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> d[i];
        sd[i] = sd[i - 1] + d[i];
    }

    for ( int i = 1; i <= n; i++ ) {
        int k = i, c = 0;
        for ( int j = i + 1; j <= n; j++ ) {
            while ( k > 0 && sd[i] - sd[k] < sd[j] - sd[i] )
                k--;

            dp[i][j] = max( dp[i][j], dp[k][i] + c );
            if ( sd[i] - sd[k] == sd[j] - sd[i] )
                c++;

        }
        for ( int j = i; j <= n; j++ )
            dp[i][j] = max( dp[i][j], max( dp[i - 1][j], dp[i][j - 1] ) );
    }

    int ans = 0;
    for ( int i = 0; i <= n; i++ )
        ans = max( ans, dp[i][n] );

    cout << ans;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...