Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream
题目连接:
http://www.codeforces.com/contest/686/problem/A
Description
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with d ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take d ice cream packs comes to the house, then Kay and Gerda will give him d packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input
The first line contains two space-separated integers n and x (1 ≤ n ≤ 1000, 0 ≤ x ≤ 109).
Each of the next n lines contains a character '+' or '-', and an integer di, separated by a space (1 ≤ di ≤ 109). Record "+ di" in i-th line means that a carrier with di ice cream packs occupies i-th place from the start of the queue, and record "- di" means that a child who wants to take di packs stands in i-th place
Output
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Sample Input
5 7
- 5
- 10
- 20
- 40
- 20
Sample Output
22 1
Hint
题意
有n个事件,你一开始有x个冰淇淋
如果事件为+ x的话,那么就是你的冰淇淋增加x
如果事件为- x的话,表示有个孩子来买x个冰淇淋,那么冰淇淋-=x,如果不够的话,就不减,反而增加一个坏孩子的数量
问你最后剩多少冰淇淋,以及坏孩子的数量是多少
题解:
水题
代码
#include<bits/stdc++.h>
using namespace std;
int n;
long long x;
string op;
int p;
int main()
{
scanf("%d%lld",&n,&x);
int ans=0;
for(int i=1;i<=n;i++){
cin>>op>>p;
if(op=="+"){
x+=p;
}
else{
if(x>=p)x-=p;
else ans++;
}
}
cout<<x<<" "<<ans<<endl;
}
Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题的更多相关文章
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Round #384 (Div. 2) A. Vladik and flights 水题
A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
随机推荐
- HDU 6215 2017Brute Force Sorting 青岛网络赛 队列加链表模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给你长度为n的数组,定义已经排列过的串为:相邻两项a[i],a[i+1],满足a[i]&l ...
- Django-模板继承、包含和静态文件配置
一.模板继承 模板继承可以减少页面内容的重复定义,实现页面内容的重用 典型应用:网站的头部.尾部是一样的,这些内容可以定义在父模板中,子模板不需要重复定义 block标签:在父模板中预留区域,在子模板 ...
- 在jsp页面中设置了远程验证,在初始化时必须预先调用一次。
参考链接:http://code.taobao.org/p/sztaotao/diff/5/trunk/code/src/main/webapp/webpage/modules/sys/roleFor ...
- thinkphp调试
Sql调试
- 多路复用IO与NIO
最近在学习NIO相关知识,发现需要掌握的知识点非常多,当做笔记记录就下. 在学NIO之前得先去了解IO模型 (1)同步阻塞IO(Blocking IO):即传统的IO模型. (2)同步非阻塞IO(No ...
- LongAdder类学习笔记
优秀原文 LongAdder | LongAccumulator简介 源码阅读:全方位讲解LongAdder 说到LongAdder,不得不提的就是AtomicLong.AtomicLong是JDK1 ...
- Filebeat入门
一.安装filebeat 简介 Beats 是安装在服务器上的数据中转代理. Beats 可以将数据直接传输到 Elasticsearch 或传输到 Logstash . Beats 有多种类型,可以 ...
- 推进"五通一平":手淘技术"三大容器 五大方案"首次整体亮相 百川开放升级
在云栖大会上,马云提出五个“新”,新零售.新制造.新金融.新技术和新能源,称将对各行各业造成巨大的影响,成为决定未来成败的关键.而五个新的实现,也必须是各行各业共同推进,整个生态共同受益的结果.继10 ...
- js交互
Js和native交互的方法与问题 实现JS和Native交互有两种方式: 第一种:shouldOverrideUrlLoading(WebView view, String url) 通过给WebV ...
- ABP zero 3.2 发布
v3.2.0 (2017-03-07) Common Tenant based UI customizations (allow tenants to upload custom CSS and lo ...