1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin>>n;
    vector<int> V2(n);
    long long sum=0;
    for(int &i:V2){cin>>i;sum+=i;}
    if(sum<0){
        cout<<"-1";
        return 0;
    }
    long long act=0;
    vector<long long> V;
    V.push_back(act);
    for(int i:V2){
        act+=i;
        //cout<<act<<" ";
        if(act<0 || act>sum)continue;
        auto it=upper_bound(V.begin(), V.end(), act);
        //cout<<it-V.begin()<<"\n";
        if(it==V.end())V.push_back(act);
        else *it=act;
    }
    cout<<n-V.size()+1;
}