Submission #641114

#TimeUsernameProblemLanguageResultExecution timeMemory
641114andreast12Bigger segments (IZhO19_segments)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define fi first #define se second const int mod=1e9+7, maxn=5e5+5; ll n, a[maxn], ans, sum; pair<ll, ll> last; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; last={a[1], 1}; ans=1; for(int i=2; i<=n; i++) { sum+=a[i]; if(sum>=last.fi) { while(true) { if(last.fi+a[last.se+1]<=sum-a[last.se+1]) { last.fi+=a[last.se+1]; sum-=a[last.se+1]; last.se++; } else break; } ans++; last={sum, i}; sum=0; } } 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...