Submission #882824

#TimeUsernameProblemLanguageResultExecution timeMemory
882824preskoBigger segments (IZhO19_segments)C++14
0 / 100
0 ms348 KiB
#include<iostream> #include<bits/stdc++.h> #define MAXN 500010 using namespace std; long long a[MAXN]; vector<pair<long long,int>> order; void try_order(int curr, int n) { int now=order.size()-1,last=n; for(int i=now;i>=0;i--) { if(last-order[i].second==1)break; bool fl=1; for(int j=order[i].first;j<=last;j++) { if(order[i].first<=curr)break; order[i].first-=a[j]; order[i-1].first+=a[j]; order[i].second++; fl=0; } last=order[i].second; if(fl){order.push_back({curr,n});return;} } } int main() { int n; ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } order.push_back({a[1],1}); long long last=a[1],curr=0,st=2; for(int i=2;i<=n;i++)//could be combined with input { curr+=a[i]; if(curr>=last) { order.push_back({curr,st}); last=curr; curr=0; st=i+1; } } if(curr)try_order(curr,n); cout<<order.size()<<"\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...