Submission #370417

#TimeUsernameProblemLanguageResultExecution timeMemory
370417casperwangBigger segments (IZhO19_segments)C++14
37 / 100
1591 ms3052 KiB
#include <bits/stdc++.h> #define int long long #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 500000; int n; int a[MAXN+1]; int pre[MAXN+1]; pii dp[MAXN+1]; int ans; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], pre[i] = pre[i-1] + a[i]; dp[1] = pii(1, -a[1]); for (int i = 2; i <= n; i++) { dp[i] = dp[i-1], dp[i].ss -= a[i]; for (int j = 1; j < i; j++) { if (pre[i] - pre[j] >= -dp[j].ss) { dp[i] = max(dp[i], pii(dp[j].ff + 1, pre[j] - pre[i])); } } assert(dp[i].ff >= dp[i-1].ff); } cout << dp[n].ff << '\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...