Submission #1007355

#TimeUsernameProblemLanguageResultExecution timeMemory
1007355Alihan_8Bigger segments (IZhO19_segments)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <int> a(n); for ( auto &u: a ){ cin >> u; } int cnt = 1, lst = a[0], i = 1; while ( i < n ){ int j = i, s = 0; while ( j < n && s < lst ){ s += a[j++]; } if ( s < lst ) break; while ( i < j && lst + a[i] <= s - a[i] ){ s -= a[i]; lst += a[i++]; } swap(lst, s); i = j; cnt++; } cout << cnt; cout << '\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...