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. JS - 属性描述符各配置的默认值的注意事项

    通过字面量或者obj.x = 1;创建的属性 与 通过Object.defineProperty创建的属性,他们的属性描述符的默认值是不同的,前者都为true,后者都为false.

  2. Wordpress网站中添加百度统计代码

    百度统计是流量分析平台,帮助收集网站访问数据,提供流量趋势.来源分析.转化跟踪.页面热力图.访问流等多种统计分析服务,同时与百度搜索.百度推广.云服务无缝结合,为网站的精细化运营决策提供数据支持,进而 ...

  3. TP3.2.3 页面跳转后 Cookie 失效 —— 参考解决方案

    一.问题描述 接手一个项目,使用ThinkPhp3.2.3,在线上环境( Centos7.4 + Nginx1.14 + MySQL5.7 + PHP7.2.4 )运行没有问题, 在本地环境( php ...

  4. Spark提交任务(Standalone和Yarn)

    Spark Standalone模式提交任务 Cluster模式: ./spark-submit  \--master spark://node01:7077  \--deploy-mode clus ...

  5. linux-shell——03

    mkdir 创建一个新目录格式: mkdir [选项-p][路径]目录名 -p 递归创建多级目录 mkdir -p b/c/e/f/g rmdir 删除一个空目录 touch 创建一个空文件,更新文件 ...

  6. python开发基础之字符编码、文件处理和函数基础

    字符编码 为什么要有字符编码? 字符编码是为了让计算机能识别我们人写的字符,因为计算机只认识高低电平,也就是二进制数"0","1". 一个文件用什么编码方式存储 ...

  7. python面向对象三大特性

    面向对象的三大特性: 封装.继承和多态 一.封装 封装,顾名思义就是将内容封装到某个地方,以后可以直接调用被封装到某处的内容. - 将内容封装到某处 - 从某处调用被封装的内容 第一步,将内容封装到某 ...

  8. 5,版本控制git --标签管理

    打标签 像其他版本控制系统(VCS)一样,Git 可以给历史中的某一个提交打上标签,以示重要. 比较有代表性的是人们会使用这个功能来标记发布结点(v1.0 等等). 在本节中,你将会学习如何列出已有的 ...

  9. 《Cracking the Coding Interview》——第16章:线程与锁——题目5

    2014-04-27 20:16 题目:假设一个类Foo有三个公有的成员方法first().second().third().请用锁的方法来控制调用行为,使得他们的执行循序总是遵从first.seco ...

  10. DOS程序员手册(十二)

    DOS可安全使用 610页 在DOS控制台I/O操作进行轮询循环时,有规律地调用中断,以便允许终止 并驻留(TSR)程序(如适用于DOS的实用程序PRINT.COM),知道它可安全 地使用文件操作和其 ...