CF1398E.Two Types of Spells

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells.

There are two types of spells: fire spell of power xx deals xx damage to the monster, and lightning spell of power yy deals yy damage to the monster and doubles the damage of the next spell Polycarp casts. Each spell can be cast only once per battle, but Polycarp can cast them in any order.

For example, suppose that Polycarp knows three spells: a fire spell of power 55 , a lightning spell of power 11 , and a lightning spell of power 88 . There are 66 ways to choose the order in which he casts the spells:

  • first, second, third. This order deals 5+1+28=225 + 1 + 2 \cdot 8 = 22 damage;
  • first, third, second. This order deals 5+8+21=155 + 8 + 2 \cdot 1 = 15 damage;
  • second, first, third. This order deals 1+25+8=191 + 2 \cdot 5 + 8 = 19 damage;
  • second, third, first. This order deals 1+28+25=271 + 2 \cdot 8 + 2 \cdot 5 = 27 damage;
  • third, first, second. This order deals 8+25+1=198 + 2 \cdot 5 + 1 = 19 damage;
  • third, second, first. This order deals 8+21+25=208 + 2 \cdot 1 + 2 \cdot 5 = 20 damage.

Initially, Polycarp knows 00 spells. His spell set changes nn times, each time he either learns a new spell or forgets an already known one. After each change, calculate the maximum possible damage Polycarp may deal using the spells he knows.

输入格式

The first line contains one integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of changes to the spell set.

Each of the next nn lines contains two integers tptp and dd ( 0tpi10 \le tp_i \le 1 ; 109d109-10^9 \le d \le 10^9 ; di0d_i \neq 0 ) — the description of the change. If tpitp_i if equal to 00 , then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.

If di>0d_i > 0 , then Polycarp learns a spell of power did_i . Otherwise, Polycarp forgets a spell with power di-d_i , and it is guaranteed that he knew that spell before the change.

It is guaranteed that the powers of all spells Polycarp knows after each change are different (Polycarp never knows two spells with the same power).

输出格式

After each change, print the maximum damage Polycarp can deal with his current set of spells.

输入输出样例

  • 输入#1

    6
    1 5
    0 10
    1 -5
    0 5
    1 11
    0 -10

    输出#1

    5
    25
    10
    15
    36
    21
首页