Submission #545557

#TimeUsernameProblemLanguageResultExecution timeMemory
545557iulia13Bigger segments (IZhO19_segments)C++14
13 / 100
1 ms308 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, v[N]; struct ura{ int seg, prv; } dp[N]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> v[i]; v[i] += v[i - 1]; } dp[1] = {1, 0}; for (int i = 1; i <= n; i++) { if (dp[i].seg < dp[i - 1].seg || (dp[i].seg == dp[i - 1].seg && dp[i].prv < dp[i - 1].prv)) dp[i] = dp[i - 1]; ///i e capatul intervalului vechi! int st = 1, dr = n, j = n + 1; while (st <= dr) { int mid = (st + dr) / 2; if (2 * v[i] - v[dp[i].prv] <= v[mid]) { j = mid; dr = mid - 1; } else st = mid + 1; } ura x = {dp[i].seg + 1, i}; if (dp[j].seg < x.seg || (dp[j].seg == x.seg && dp[j].prv < x.prv)) dp[j] = x; } cout << dp[n].seg; 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...