題目
原題鏈接:A. Free Ice Cream
題意
最開始有m個冰淇淋,每次輸入一個+/-和數字,+代表進貨,-代表送出,若送出的數量大于持有數量,則計數器+1。問最后有多少冰淇淋和計數器。
代碼
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,c=0;
long long sum,t;
char s;
scanf("%d%lld",&n,&sum);
while(n--) {
getchar();
scanf("%c %lld",&s,&t);
if(s=='-') {
if(t>sum) {
c++;
} else {
sum-=t;
}
} else {
sum+=t;
}
}
printf("%lld %d\n",sum,c);
return 0;
}