Submission #990903

#TimeUsernameProblemLanguageResultExecution timeMemory
990903ToniBBigger segments (IZhO19_segments)C++17
37 / 100
1561 ms7508 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int, ll> pii; const int N = 5e5 + 2; int n, a[N]; pii dp[N]; ll pre[N]; ll sum(int i, int j) { if (i) return pre[j] - pre[i - 1]; return pre[j]; } pii cmp(pii x, pii y) { if (x.X == y.X) { if (x.Y < y.Y) return x; return y; } if (x.X > y.X) return x; return y; } 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]; dp[0] = {1, a[0]}; for (int i = 1; i < n; ++i) { for (int j = 0; j < i; ++j) { if (sum(j + 1, i) >= dp[j].Y) { dp[i] = cmp(dp[i], {dp[j].X + 1, sum(j + 1, i)}); } } dp[i] = cmp(dp[i], {1, pre[i]}); } cout << dp[n - 1].X << "\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...