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. Maven - 依赖冲突

    依赖冲突有两个规则: 短路优先范例:A -> B -> C -> X-2.0.0A -> D -> X-1.0.0那么A -> X-1.0.0这个版本 先声明优先范 ...

  2. Python变量、赋值及作用域

    ## 变量 - 指向唯一内存地址的一个名字 - 目的是为了更方便地引用内存中的值 - 可以使用id(变量)函数来查看变量的唯一id值,若两者id值相同,则表示两个变量指向同一地址,两个变量的值完全相同 ...

  3. 实例讲解如何利用jQuery设置图片居中放大或者缩小

    大家有没有见过其他网站的图片只要鼠标放上去就能放大,移出去的时候就能缩小,而且一直保持居中显示!其实jQuery提供一个animate函数可以使图片放大和缩小,只要改变图片的长和高就OK啦!但是ani ...

  4. selenium库:自动化测试工具

    爬虫中主要用来解决Javascript渲染问题 1.声明浏览器对象: from selenium import webdriver browser = webdriver.浏览器名() 2.访问页面: ...

  5. Requests库:python实现的简单易用的http库

    1.get请求: get(url, params, headers) 2.json 解析 3.content 获取二进制内容 4.headers 添加 5.post请求:post(url,data,h ...

  6. Triangular Sums 南阳acm122

    Triangular Sums 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 The nth Triangular number, T(n) = 1 + … + n ...

  7. POJ3682 概率DP

    King Arthur's Birthday Celebration Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3575 ...

  8. 2018Ec-Final比赛总结

    一场匆忙的旅程. NCC_9754_ Victory的最后一场比赛终究没能victory. 去的时候晕车到吐了两次,到宾馆吃完饭直接睡了,但还是两天都昏昏沉沉的头疼的厉害,第二天直接步行去了西工大体育 ...

  9. Codeforces Round #482 (Div. 2) :C - Kuro and Walking Route

    题目连接:http://codeforces.com/contest/979/problem/C 解题心得: 题意就是给你n个点,在点集中间有n-1条边(无重边),在行走的时候不能从x点走到y点,问你 ...

  10. DbVisualizer 解决中文乱码问题

    在SQL Commander中,sql语句中如果有中文,显示是‘口口口’. 解决办法如下: 在Tools->tool Properties->General->Appearance- ...