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 水题的更多相关文章

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

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

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

  4. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

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

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

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

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

  9. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

随机推荐

  1. DRM/KMS 基本组件介绍

    Each DRM device provides access to manage which monitors and displays are currently used and what fr ...

  2. C# 调用WSDL接口及方法

    1.首先需要清楚WSDL的引用地址 如:http://XX.XX.4.146:8089/axis/services/getfileno?wsdl 上述地址的构造为 类名getfileno. 2.在.N ...

  3. order by 的列名不能参数化,要拼sql

    from T_COMPANY c join T_COMPANY_POSITION p on c.ID = p.COMPANYID order by :type desc nulls last; 最初不 ...

  4. html-示例代码

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html" xml ...

  5. 数据库--mysql介绍

    一:什么是数据库 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库, 每个数据库都有一个或多个不同的API用于创建,访问,管理,搜索和复制所保存的数据. 我们也可以将数据存储在文件 ...

  6. Codeforces 793C - Mice problem(几何)

    题目链接:http://codeforces.com/problemset/problem/793/C 题目大意:给你一个捕鼠器坐标,和各个老鼠的的坐标以及相应坐标的移动速度,问你是否存在一个时间点可 ...

  7. C++静态成员的应用

    当在类外部定义静态成员时,不能重复使用static关键字 静态成员函数不包含this指针(无论是显示还是隐式使用) 静态成员可以通过类对象进行访问,也可以通过类进行访问 静态成员不是由构造函数初始化的 ...

  8. Java工程师知识图谱

    一.Java工程师知识图谱(思维导图版) 二.Java工程师知识图谱(图文版) 三.Java工程师知识图谱(文字版) http://note.youdao.com/noteshare?id=615da ...

  9. Oracle学习笔记:11g服务介绍及哪些服务必须开启?

    由于工作环境中oracle版本为10g,不支持行转列函数pivot,特在自己电脑上安装了oracle 11g,但因为不经常使用,便把服务自动启动给关闭了,只在需要使用时手动启动,因此记录一下需要启动的 ...

  10. Winafl学习笔记

    最近在跟师傅们学习Winafl,也去搜集了一些资料,有了一些自己的理解,就此记录一下. Winafl是一个运行时插桩工具,可以提高crash的捕获率. 同时也有自己的遗传算法,可以根据代码覆盖程度进行 ...