This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
if(order[i].second==last-1)return;
order[i].first-=a[j];
order[i-1].first+=a[j];
order[i].second++;
fl=0;
}
last=order[i].second;
curr=order[i].first;
if(fl){order.push_back({n,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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |