Codeforces #359 A. Free Ice Cream
传送门:http://codeforces.com/contest/686/problem/A
题目大意
有 n 个操作,初始 x 元钱。
每个操作表示为 +/- p ,表示增加或者减少p元。
减少时若现金不足 p 元,则无法支付(不支付)。
统计最后持有金和无法支付次数。
题解
模拟暴力
代码
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 |
#include<cstdio> #include<iostream> using namespace std; int m; int dis=0; long long res; char opt[5]; int cmd; int main(){ scanf("%d%d",&m,&cmd); res=cmd; for (int i=1;i<=m;i++){ scanf("%s%d",opt,&cmd); if (opt[0]=='+'){ res=res+(long long)cmd; }else{ if (cmd>res){ dis++; }else{ res=res-(long long)cmd; } } } cout<<res<<" "<<dis<<endl; return 0; } |

原文链接:Codeforces #359 A. Free Ice Cream
WNJXYKの博客 版权所有,转载请注明出处。
还没有任何评论,你来说两句吧!