ソースコード
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long int n,c,d,e,f;
int b[100000];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
c+=b[i];
}
for (int i = 0; i < n; i++) {
e+= b[i];
}
for (int i = n; i > n; i--) {
if (c >= 0) {
d = i;
return 0;
}
c -= b[i];
}
for (int i = 0; i < n; i++) {
if (e >= 0) {
f = n - i;
return 0;
}
e -= b[i];
}
if (d == f&&d == 0) {
cout << -1 << endl;
}
else {
if (d >= f) {
cout << d << endl;
}
else {
cout << f << endl;
}
}
}