CF686A.Free Ice Cream

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

在与魔镜的冒险之后,凯和格尔达回到了家中,有时会在夏天免费向孩子们发放冰淇淋。

一天开始时,他们有 xx 盒冰淇淋。由于冰淇淋是免费的,人们甚至在深夜就开始在凯和格尔达家门前排队。队列中的每个人要么想为自己和朋友们取走若干盒冰淇淋,要么想给凯和格尔达送若干盒冰淇淋(运送冰淇淋的“送货员”也必须排在同一支队伍中)。

  • 如果一名送货员带着 dd 盒冰淇淋来到家中,则凯和格尔达会收下他所有的冰淇淋盒;
  • 如果一名孩子想取走 dd 盒冰淇淋,则当凯和格尔达手头有足够多的冰淇淋时,他们会给他 dd 盒;否则,这名孩子将一盒也得不到,并伤心地离开。

凯希望知道所有人离开队伍后他们剩余的冰淇淋数量,而格尔达则希望知道有多少名孩子因未得到冰淇淋而感到伤心。

输入格式

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 d__i, separated by a space (1 ≤ d__i ≤ 109). Record "+ d__i" in i-th line means that a carrier with d__i ice cream packs occupies i-th place from the start of the queue, and record "- d__i" means that a child who wants to take d__i packs stands in i-th place.

第一行包含两个以空格分隔的整数 nn 和 xx(1 ≤ n ≤ 10001 \leq n \leq 1000,0 ≤ x ≤ 1090 \leq x \leq 10^9)。

接下来的 nn 行中,每行包含一个字符 '+' 或 '-',后跟一个整数 did_i,二者以空格分隔(1 ≤ di ≤ 1091 \leq d_i \leq 10^9)。第 ii 行中的记录 '+ $d_i$ 表示一位携带 did_i 盒冰淇淋的送货员占据了队列中从队首开始的第 ii 个位置;而记录 '- $d_i$ 表示一位想要购买 did_i 盒冰淇淋的小孩站在了队列中从队首开始的第 ii 个位置。

输出格式

Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.

输出两个用空格分隔的整数——所有操作完成后剩余的冰淇淋包装数量,以及沮丧离开家的孩子数量。

输入输出样例

  • 输入#1

    5 7
    + 5
    - 10
    - 20
    + 40
    - 20

    输出#1

    22 1
  • 输入#2

    5 17
    - 16
    - 2
    - 98
    + 100
    - 98

    输出#2

    3 2

说明/提示

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.

考虑第一个样例。

  1. 最初,凯和格尔达有 7 盒冰淇淋。
  2. 快递员又送来了 5 盒,因此他们现在共有 12 盒。
  3. 一个小孩索要 10 盒,并成功获得。此时仅剩 2 盒。
  4. 另一个小孩索要 20 盒。凯和格尔达没有这么多,因此该小孩失望地离开了。
  5. 快递员又送来了 40 盒,此时凯和格尔达共有 42 盒。
  6. 小孩索要 20 盒并成功获得。此时还剩 22 盒。

输入解题思路,AI测评打分。不知道怎么写?

首页