Submission #990884

#TimeUsernameProblemLanguageResultExecution timeMemory
990884ToniBBigger segments (IZhO19_segments)C++17
13 / 100
26 ms13084 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3005; typedef long long ll; int n, a[N], dp[N][N]; ll pre[N]; ll sum(int i, int j) { if (i) return pre[j] - pre[i - 1]; return pre[j]; } int main(){ cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; pre[0] = a[0]; for (int i = 1; i < n; ++i) pre[i] = a[i] + pre[i - 1]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) dp[i][j] = -1e9; } for (int i = 0; i < n; ++i) { dp[0][i] = 1; } for (int i = 1; i < n; ++i) { for (int j = i; j < n; ++j) { for (int k = 0; k < i; ++k) { if (sum(i, j) >= sum(k, i - 1)) dp[i][j] = max(dp[i][j], dp[k][i - 1] + 1); } } } int ans = 0; for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]); int gr = 0; ll sum = 0, cur = 0; for (int i = 0; i < n; ++i) { cur += a[i]; if (cur >= sum) { sum = cur; ++gr; cur = 0LL; } } assert(gr + 5 >= ans); cout << ans << "\n"; 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...