Submission #370411

#TimeUsernameProblemLanguageResultExecution timeMemory
370411casperwangBigger segments (IZhO19_segments)C++14
13 / 100
1 ms492 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 L, R; 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]); L = 0, R = 1; for (int i = 2; i <= n; i++) { int l = L, r = R; while (l < r) { int mid = (l + r + 1) >> 1; if (pre[i] - pre[mid] >= -dp[mid].ss) l = mid; else r = mid-1; } dp[i] = pii(dp[l].ff + 1, pre[l] - pre[i]); L = l; R++; } 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...