#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n; long long s, a; vector <long long> v; vector <long long>::iterator it; int main () { scanf("%d", &n); scanf("%lld", &s); v.push_back(0); for (int i = 1; i < n; ++i) { scanf("%lld", &a); if (s >= v.back()) v.push_back(s); else if (s >= 0) { it = upper_bound(v.begin(), v.end(), s); *it = s; } s += a; } if (s < 0) { printf("-1\n"); return 0; } for (it = v.begin(); it != v.end(); ++it) { if (s >= *it) n--; else break; } printf("%d\n", n); return 0; }
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 31 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n; long long s, a; vector <long long> v; vector <long long>::iterator it; int main () { scanf("%d", &n); scanf("%lld", &s); v.push_back(0); for (int i = 1; i < n; ++i) { scanf("%lld", &a); if (s >= v.back()) v.push_back(s); else if (s >= 0) { it = upper_bound(v.begin(), v.end(), s); *it = s; } s += a; } if (s < 0) { printf("-1\n"); return 0; } for (it = v.begin(); it != v.end(); ++it) { if (s >= *it) n--; else break; } printf("%d\n", n); return 0; } |