Submission #332339

#TimeUsernameProblemLanguageResultExecution timeMemory
332339dolphingarlicBigger segments (IZhO19_segments)C++14
37 / 100
1587 ms2924 KiB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll a[500001], pref[500001];
pair<int, ll> dp[500001];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
        for (int j = 0; j < i; j++) if (dp[j].second >= pref[j] - pref[i])
            dp[i] = max(dp[i], {dp[j].first + 1, pref[j] - pref[i]});
    }
    cout << dp[n].first;
    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...