제출 #883206

#제출 시각아이디문제언어결과실행 시간메모리
883206preskoBigger segments (IZhO19_segments)C++14
0 / 100
1 ms348 KiB
#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].second<order[ind+1].second)
    {
        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 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...