Submission #882836

#TimeUsernameProblemLanguageResultExecution timeMemory
882836preskoBigger segments (IZhO19_segments)C++14
0 / 100
1 ms504 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 last, int n) { int now=order.size()-1; for(int i=now;i>=0;i--) { //if(last-order[i].second==1)break; bool fl=1; int be=order[i].second; for(int j=be;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; if(order[i].second==last-1)return; } 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,st,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...