A. Free Ice Cream
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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.

Examples
Input
5 7
+ 5
- 10
- 20
+ 40
- 20
Output
22 1
Input
5 17
- 16
- 2
- 98
+ 100
- 98
Output
3 2
Note

Consider the first sample.

  1. Initially Kay and Gerda have 7 packs of ice cream.
  2. Carrier brings 5 more, so now they have 12 packs.
  3. A kid asks for 10 packs and receives them. There are only 2 packs remaining.
  4. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed.
  5. Carrier bring 40 packs, now Kay and Gerda have 42 packs.
  6. 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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #359 (Div. 1)

    A http://codeforces.com/contest/685/standings 题意:给你n和m,找出(a,b)的对数,其中a满足要求:0<=a<n,a的7进制的位数和n-1的 ...

  4. 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 ...

  5. Codeforces Round #359 (Div. 1) A. Robbers' watch 暴力

    A. Robbers' watch 题目连接: http://www.codeforces.com/contest/685/problem/A Description Robbers, who att ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #359 (Div. 2) C. Robbers' watch 搜索

    题目链接:http://codeforces.com/contest/686/problem/C题目大意:给你两个十进制的数n和m,选一个范围在[0,n)的整数a,选一个范围在[0,m)的整数b,要求 ...

  9. Codeforces Round #359(div 2)

    A:= v = B:^ w ^ C:一天n个小时,一个小时m分(n,m十进制),一个手表有两部分,左边表示时,右边表示分,但都是7进制,而且手表上最多只能有7个数字且数字不能重复,现在要你算出能正确表 ...

  10. 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 ...

随机推荐

  1. tcp服务端socket

    import socket if __name__ == '__main__': # 创建tcp服务端socket tcp_server_socket = socket.socket(socket.A ...

  2. django+xadmin在线教育平台(十二)

    6-4 用form实现登录-1 上面我们的用户登录的方法是基于函数来做的.本节我们做一个基于类方法的版本. 要求对类的继承有了解. 基础教程中基本上都是基于函数来做的,其实更推荐基于类来做.基于类可以 ...

  3. django+xadmin在线教育平台(八)

    4-5 user modesl.py设计 循环引用: 设计app时每个app都有model   mark 如图:我们在user中定义usercourse记录用户学习的课程.会有两个外键:user和co ...

  4. 基于Select模型通信程序的编写,编译和执行

    任务目标 编写Win32程序模拟实现基于Select模型的两台计算机之间的通信,要求编程实现服务器端与客户端之间双向数据传递.客户端向服务器端发送"计算从1到100的奇数和",服务 ...

  5. pip更改国内源

    国内源: 阿里云 http://mirrors.aliyun.com/pypi/simple/中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/豆瓣(dou ...

  6. Leetcode 653. 两数之和 IV - 输入 BST

    题目链接 https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/ 题目描述 给定一个二叉搜索树和一个目标结果,如果 B ...

  7. 十一、mysql老是停止运行该怎么解决

    mysql老是停止运行该怎么解决 你可能还会遇到无法启动mysql的错误 解决方法如下:      

  8. linux中如何解决克隆后的电脑的问题

    1.如何解决克隆后的电脑的网络问题 克隆出来的电脑,IP地址,网卡都是重复的,不能直接使用,需要修改 1)vim  /etc/udev/rules.d/70-persistent-net.rules ...

  9. 《Cracking the Coding Interview》——第11章:排序和搜索——题目4

    2014-03-21 21:28 题目:给定一个20GB大小的文本文件,每一行都是一个字符串.请设计方法将这个文件里的字符串排序. 解法:请看下面的注释. 代码: // 11.4 Given a fi ...

  10. 《Cracking the Coding Interview》——第3章:栈和队列——题目1

    2014-03-18 03:19 题目:用一个数组实现3个栈. 解法: 首先我想过让三个栈动态决定长度.要么左右各一个向中间靠拢,要么三个穿插着,后来都觉得实现起来太复杂,而且思路总有各种功能缺陷,会 ...