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;
bool try_order(int ind, int n)
{
if(order[ind].first<=order[ind+1].first)return 1;
if(ind==0 && order[ind].first>order[ind+1].first)return 0;
while(order[ind].first>order[ind-1].first)
{
order[ind].first-=a[order[ind].second];
order[ind-1].first+=a[order[ind].second];
order[ind].second++;
if(try_order(ind-1,n))return 1;
}
return 0;
}
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,v1;
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;
}
}
v1=order.size();
if(curr)
{
order.push_back({curr,last});
if(try_order(order.size()-2,n))v1++;
}
cout<<v1<<"\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... |