Submission #771749

#TimeUsernameProblemLanguageResultExecution timeMemory
771749JomnoiBigger segments (IZhO19_segments)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5 + 5; long long A[MAX_N], dp1[MAX_N], dp2[MAX_N], maxA[MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; A[i] += A[i - 1]; } dp2[1] = 1; for (int i = 1; i <= N; i++) { maxA[i] = max(maxA[i - 1], maxA[i]); dp1[i] = A[i] - maxA[i]; dp2[i] = max(dp2[i], dp2[i - 1]); int l = i + 1, r = N; while (l < r) { int mid = (l + r) / 2; if (A[mid] - A[i] >= dp1[i]) r = mid; else l = mid + 1; } if (maxA[l] < A[i]) { maxA[l] = A[i]; dp2[l] = dp2[i] + 1; } } cout << dp2[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...