Submission #1127762

#TimeUsernameProblemLanguageResultExecution timeMemory
1127762VMaksimoski008Bigger segments (IZhO19_segments)C++17
37 / 100
1596 ms2116 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; signed main() { int n; cin >> n; vector<int> a(n+1); vector<ll> pref(n+1); for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=n; i++) pref[i] = pref[i-1] + a[i]; vector<int> dp(n+1), last(n+1); dp[0] = 0; for(int i=1; i<=n; i++) { for(int j=i; j>=1; j--) { if(2 * pref[j] - pref[last[j]] <= pref[i] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; last[i] = j; } } } cout << dp[n] + 1 << '\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...