Codeforces Round #359 (Div. 2) A
2 seconds
256 megabytes
standard input
standard output
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.
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.
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
5 7
+ 5
- 10
- 20
+ 40
- 20
22 1
5 17
- 16
- 2
- 98
+ 100
- 98
3 2
Consider the first sample.
- Initially Kay and Gerda have 7 packs of ice cream.
- Carrier brings 5 more, so now they have 12 packs.
- A kid asks for 10 packs and receives them. There are only 2 packs remaining.
- Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
- Carrier bring 40 packs, now Kay and Gerda have 42 packs.
- Kid asks for 20 packs and receives them. There are 22 packs remaining.
题意:初始x个冰淇淋 按照操作符‘+’, ‘-’ 增减 统计最终剩余冰淇淋 和不能满足增减的次数
题解:水题
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
using namespace std;
ll n,x,b;
char a;
int main()
{
scanf("%I64d %I64d",&n,&x);
ll sum=x;
ll flag=;
for(int i=;i<=n;i++)
{
getchar();
scanf("%c %d",&a,&b);
if(a=='+')
sum+=b;
if(a=='-')
{
if(sum>=b)
sum-=b;
else
flag++;
}
}
cout<<sum<<" "<<flag<<endl;
return ;
}
Codeforces Round #359 (Div. 2) A的更多相关文章
- Codeforces Round #359 (Div. 2)C - Robbers' watch
C. Robbers' watch time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch (暴力DFS)
题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b &l ...
- Codeforces Round #359 (Div. 1)
A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...
- Codeforces Round #359 (Div. 1) B. Kay and Snowflake dfs
B. Kay and Snowflake 题目连接: http://www.codeforces.com/contest/685/problem/B Description After the pie ...
- Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力
A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...
- Codeforces Round #359 (Div. 2) B. Little Robber Girl's Zoo 水题
B. Little Robber Girl's Zoo 题目连接: http://www.codeforces.com/contest/686/problem/B Description Little ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索
题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...
- Codeforces Round #359(div 2)
A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...
- Codeforces Round #359 (Div. 2) D. Kay and Snowflake 树DP
D. Kay and Snowflake After the piece of a devilish mirror hit the Kay's eye, he is no longer int ...
随机推荐
- nodejs 发送邮件(阿里云)
1.下载 模块 2. 编辑文件 var nodemailer = require('nodemailer'); var sendEmail = function(emailinfo,callbac ...
- RocketMQ源码分析之RocketMQ事务消息实现原理中篇----事务消息状态回查
上节已经梳理了RocketMQ发送事务消息的流程(基于二阶段提交),本节将继续深入学习事务状态消息回查,我们知道,第一次提交到消息服务器时消息的主题被替换为RMQ_SYS_TRANS_HALF_TOP ...
- ThinkPHP路由去掉隐藏URL中的index.php
官方默认的.htaccess文件 <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On ...
- 笔记-python-built-in functions-eval,exec,compile
笔记-python-built-in functions-eval,exec,compile 1. python代码执行函数 有时需要动态改变代码,也就是说代码需要是字符串格式,然后在按需要 ...
- 笔记-python-语法-super
笔记-python-语法-super 1. super 1.1. super起源 首先要理解类的继承和多继承,子类有时需要调用父类的方法, 非绑定方法: class C(B): def ...
- P1297 网线切割
P1297 网线切割 题目描述 Wonderland居民决定举行一届地区性程序设计大赛.仲裁委员会志愿负责这次赛事并且保证会组织一次有史以来最公正的比赛.为此,所有参赛者的电脑和网络中心会以星状网络连 ...
- P1875 佳佳的魔法药水
P1875 佳佳的魔法药水 题目描述 发完了 k 张照片,佳佳却得到了一个坏消息:他的 MM 得病了!佳佳和大家一样焦急 万分!治好 MM 的病只有一种办法,那就是传说中的 0 号药水 ……怎么样才能 ...
- ImageButton的坑 ImageButton 有问题
最近在用ImageButton,发现,我如果new ImageButton,并且 设置Warp_content,但是它并不会正真的warp,它会有一个边框. 不知道怎么回事. 后来,在代码里面使用Im ...
- 5.bootstrap栅格 清除浮动
只要用到栅格,就注意要清除浮动,清除方法就是在父元素的class上加一个clearfix 1.情景: . <div class="col-sm-7"> <div ...
- GCD那些事儿
GCD GCD,全名Grand Central Dispatch,中文名郭草地,是基于C语言的一套多线程开发API,一听名字就是个狠角色,也是目前苹果官方推荐的多线程开发方式.可以说是使用方便,又不失 ...