Untitled

mail@pastecode.io avatar
unknown
plain_text
7 days ago
466 B
4
Indexable
Never
void solve(){
    ll n;cin>>n;
    ipar(a,n);
    if(is_sorted(a)){
        cout<<a[n-1]-a[0]<<"\n";
        return;
    }
    ll mx=0,mn=1e18;
    ll sum=0;
    for(int i=n-1;i>=0;i--){
        sum+=a[i];
        if(a[i]<=mn){
            mn=a[i];
            continue;
        }
        ll av=sum/(n-i);
        if(sum%(n-i)!=0){
            mx=av+1;
        }else{
            mx=av;
        }
        mn=av;
    }
    cout<<mx-mn<<"\n";
}
Leave a Comment