제출 #1087504

#제출 시각아이디문제언어결과실행 시간메모리
1087504makravBigger segments (IZhO19_segments)C++14
0 / 100
0 ms452 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define pb push_back #define ff first #define sc second #define int ll void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> pref(n + 1); for (int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i - 1]; } int L = 0, R = 0, sm = pref[1], ans = 1; while (true) { int csm = 0; int j = R + 1; for (; csm < sm && j < n; j++) { csm += a[j]; } j--; if (csm >= sm) { while (R < j && pref[R + 1] - pref[L] <= pref[j + 1] - pref[R + 1]) R++; R--; L = R + 1; R = j; ans++; sm = pref[R + 1] - pref[L]; } else { cout << ans << '\n'; return; } } } signed main() { int tt = 1; #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> tt; #else ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #endif while (tt--) { solve(); } 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...