Submission #1114384

#TimeUsernameProblemLanguageResultExecution timeMemory
1114384vjudge1Bigger segments (IZhO19_segments)C++17
0 / 100
1 ms508 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; vector<int> a(n + 1), pref(n + 1); for (int i = 1; i<= n; i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } vector<pair<int, int>> dp(n + 1); dp[1] = {1, a[1]}; for (int i = 2; i <= n; i++){ int ini = 1, fin = i; while(ini < fin){ int m = (ini + fin) / 2; if (dp[m].second <= pref[i]- pref[m]){ ini = m + 1; }else fin = m; } ini--; int sum = pref[i] - pref[ini]; dp[i] = {dp[ini].first + 1, sum}; } cout << dp[n].first << endl; }
#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...