帮我看看有什么问题 0V0
by Main_Void_ @ 2023-07-21 16:48:15
```
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],ans=0,sum=0;
int main()
{
cin>>n;
for(register int i = 1; i <= n; i ++) {
cin >> a[i];
ans += a[i];
if(ans<=0) sum = max(sum, 1 - ans);
}
cout << sum;
return 0;
}
```
这是我的
by CcmCyh11140810 @ 2023-07-21 16:51:00
比如:
4
1000 -900 -600 -500
正确输出:1001
你的代码:1101
by CcmCyh11140810 @ 2023-07-21 16:59:42
@[CcmCyh11140810](/user/803862)
谢谢!我找到问题了 , 我给初始血量增加后没有顾及现有血量 ,然后改成这样就行了
```cpp
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n, Hp = 1, Hp2 = 1, x;
cin >> n;
while (n--) {
cin >> x;
if (x < 0 && Hp2 + x <= 0) {
Hp += abs(x) - Hp2 + 1;
Hp2 = 1;
}
else {
Hp2 += x;
}
}
cout << Hp;
}
```
by Main_Void_ @ 2023-07-22 15:37:47