Submission #308800

#TimeUsernameProblemLanguageResultExecution timeMemory
308800nikatamlianiBigger segments (IZhO19_segments)C++14
37 / 100
1587 ms2604 KiB
#include <bits/stdc++.h> #define f first #define s second #define ll long long using namespace std; const int N = 5e5 + 10; pair < int, ll > dp[N]; ll sum[N], n; int main() { cin >> n; for(int i = 1; i <= n; ++i) cin >> sum[i], sum[i] += sum[i - 1]; for(int i = 1; i <= n; ++i) { // int l = 1, r = i, ans = 1; // while(r >= l) { // int m = l + r >> 1; // if(sum[i] - sum[m - 1] >= dp[m - 1].s) { // l = m + 1; // ans = m; // } else { // r = m - 1; // } // } // dp[i].f = dp[ans - 1].f + 1; // dp[i].s = sum[i] - sum[ans - 1]; for(int j = 0; j < i; ++j) { if(sum[i] - sum[j] >= dp[j].s) { if(dp[i].f == dp[j].f + 1) { dp[i].s = min(dp[i].s, sum[i] - sum[j]); } if(dp[i].f < dp[j].f + 1) { dp[i].s = sum[i] - sum[j]; dp[i].f = dp[j].f + 1; } } } } cout << dp[n].f << '\n'; }
#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...