제출 #769939

#제출 시각아이디문제언어결과실행 시간메모리
769939JomnoiBigger segments (IZhO19_segments)C++17
13 / 100
1 ms2388 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 3005;
const long long INF = 1e18 + 7;

long long A[MAX_N], dp[MAX_N][MAX_N];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];

        A[i] += A[i - 1];
    }

    int ans = 1;
    for (int i = 1; i <= N; i++) dp[i][0] = INF;
    for (int i = 1; i <= N; i++) dp[1][i] = A[i];
    for (int s = 2; s <= N; s++) {
        for (int i = 1, j = 1; i <= N; i++) {
            while (j <= i and (dp[s - 1][j] == INF or dp[s - 1][j] <= A[i] - A[j])) j++;

            dp[s][i] = INF;
            if (dp[s - 1][j - 1] <= A[i] - A[j - 1]) dp[s][i] = A[i] - A[j - 1];
        }

        if (dp[s][N] == INF) break;
        ans = s;
    }
    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...