Submission #155681

#TimeUsernameProblemLanguageResultExecution timeMemory
155681qkxwsmBigger segments (IZhO19_segments)C++14
37 / 100
1564 ms3300 KiB
#include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define MAXN 500013 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; int N; ll arr[MAXN], pref[MAXN]; pll dp[MAXN]; int ans; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; FOR(i, 0, N) { cin >> arr[i]; pref[i + 1] = pref[i] + arr[i]; } dp[0] = {0, 0}; //best, sum needed FOR(i, 1, N + 1) { FORD(j, i, 0) { if (pref[i] - pref[j] >= dp[j].se) { dp[i].fi = dp[j].fi + 1; dp[i].se = pref[i] - pref[j]; break; } } } ans = dp[N].fi; //choose the rightmost umber to go off of 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...