Submission #1258808

#TimeUsernameProblemLanguageResultExecution timeMemory
1258808proofyBigger segments (IZhO19_segments)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; if (!(cin >> N)) return 0; vector<long long> a(N+1); long long tot = 0; for (int i = 1; i <= N; ++i) { cin >> a[i]; tot += a[i]; } long long prev = 0, cur = 0, rem = tot; // rem = sum of tail not yet processed int start = 1; // start index of current block long long ans = 0; for (int i = 1; i <= N; ++i) { cur += a[i]; rem -= a[i]; if (cur >= prev) { if (i < N) { // leave room for at least one more block (sum >= cur) while (cur > rem && start <= i) { prev += a[start]; cur -= a[start]; ++start; } } if (cur >= prev) { // still valid to cut ++ans; prev = cur; cur = 0; start = i + 1; } } } if (ans == 0) ans = 1; // the whole array is one block cout << ans << '\n'; }
#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...