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. javascript按照指定格式获取上一个月的日期

    //get pre month//get pre month function getPreMonth() { var date=new Date().Format("yyyy-MM-dd& ...

  2. setInterval做定时器

    <script src="/js/jquery-1.8.3.min.js"></script> <script> $(function () { ...

  3. 试用Redis

    Windows 10家庭中文版,运行于VirtualBox上的Ubuntu 18.04,Redis 4.0.10, Redis,久仰大名!因为没有从事互联网行业,所以一直没有使用过.近期找工作,也隐约 ...

  4. CSS3实现扇形动画菜单特效

    CSS3实现扇形动画菜单特效 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html> <head> <meta charset=&q ...

  5. Jackson jsonToBean 忽略 Bean中不存在属性的匹配。

    1. jsonToBean时,json中有的字段,bean中没有 无法匹配时,忽略此字段,不抛出异常(默认是抛出异常的) 方案一(局部):在class上加 @JsonIgnoreProperties( ...

  6. Codeforces 2B The least round way(dp求最小末尾0)

    题目链接:http://codeforces.com/problemset/problem/2/B 题目大意: 给你一个nxn的矩形,找到一条从左上角到右下角的路径,使得该路径上所有数字的乘积的末尾0 ...

  7. 关于Eclipse连接sql server 2008的若干问题

    以下内容转自:https://www.cnblogs.com/skylarzhan/p/7619977.html Eclipse中使用SQL server 2008数据库 一.准备材料 要能够使用数据 ...

  8. SQL Server日期计算

    通常,你需要获得当前日期和计算一些其他的日期,例如,你的程序可能需要判断一个月的第一天或者最后一天.你们大部分人大概都知道怎样把日期进行分割(年.月.日等),然后仅仅用分割出来的年.月.日等放在几个函 ...

  9. Introduction to MWB Minor Mode

    Introduction to MWB Minor Mode */--> Table of Contents 1. Introduction 2. Usage 1 Introduction MW ...

  10. python之web框架(3):WSGI之web应用完善

    python之web框架(3):WSGI之web应用完善 1.上篇的web框架太low,只能实现回应固定页面.现在将它进行完善.首先将wsgi和web服务器进行分离,并给予它回复静态页面的能力. we ...