CF1398E.Two Types of Spells
提高+/省选-
通过率:0%
时间限制:3.50s
内存限制:256MB
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 x deals x damage to the monster, and lightning spell of power y deals y 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 5, a lightning spell of power 1, and a lightning spell of power 8. There are 6 ways to choose the order in which he casts the spells:
- first, second, third. This order deals 5+1+2⋅8=22 damage;
- first, third, second. This order deals 5+8+2⋅1=15 damage;
- second, first, third. This order deals 1+2⋅5+8=19 damage;
- second, third, first. This order deals 1+2⋅8+2⋅5=27 damage;
- third, first, second. This order deals 8+2⋅5+1=19 damage;
- third, second, first. This order deals 8+2⋅1+2⋅5=20 damage.
Initially, Polycarp knows 0 spells. His spell set changes n 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.
波利卡普正在玩一款电脑游戏(又一次)。在这款游戏中,他使用魔法咒语来攻击怪物。
咒语分为两种类型:
- 火焰咒语,威力为 x,对怪物造成 x 点伤害;
- 闪电咒语,威力为 y,对怪物造成 y 点伤害,并使波利卡普下一次施放的咒语的伤害翻倍。
每种咒语在一场战斗中只能施放一次,但波利卡普可以以任意顺序施放它们。
例如,假设波利卡普掌握了三个咒语:一个威力为 5 的火焰咒语、一个威力为 1 的闪电咒语、一个威力为 8 的闪电咒语。他有 6 种不同的施放顺序:
- 第一、第二、第三:造成 5+1+2⋅8=22 点伤害;
- 第一、第三、第二:造成 5+8+2⋅1=15 点伤害;
- 第二、第一、第三:造成 1+2⋅5+8=19 点伤害;
- 第二、第三、第一:造成 1+2⋅8+2⋅5=27 点伤害;
- 第三、第一、第二:造成 8+2⋅5+1=19 点伤害;
- 第三、第二、第一:造成 8+2⋅1+2⋅5=20 点伤害。
初始时,波利卡普掌握 0 个咒语。他的咒语集合共发生 n 次变化,每次变化要么学会一个新咒语,要么遗忘一个已掌握的咒语。每次变化后,请计算波利卡普利用当前掌握的所有咒语所能造成的最大可能伤害。
输入格式
The first line contains one integer n (1≤n≤2⋅105) — the number of changes to the spell set.
Each of the next n lines contains two integers tp and d (0≤tpi≤1; −109≤d≤109; di=0) — the description of the change. If tpi if equal to 0, then Polycarp learns (or forgets) a fire spell, otherwise he learns (or forgets) a lightning spell.
If di>0, then Polycarp learns a spell of power di. Otherwise, Polycarp forgets a spell with power −di, 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).
第一行包含一个整数 n(1≤n≤2⋅105),表示对法术集合进行修改的次数。
接下来的 n 行,每行包含两个整数 tp 和 d(0≤tpi≤1;−109≤d≤109;di=0),描述一次修改操作。若 tpi=0,则 Polycarp 学习(或遗忘)一个火焰法术;否则(即 tpi=1),他学习(或遗忘)一个闪电法术。
若 di>0,则 Polycarp 学习一个威力为 di 的法术;否则(即 di<0),Polycarp 遗忘一个威力为 −di 的法术,且保证在本次修改前他确实掌握该法术。
保证每次修改后 Polycarp 所掌握的所有法术的威力互不相同(即 Polycarp 不会同时掌握两个威力相同的法术)。
输出格式
After each change, print the maximum damage Polycarp can deal with his current set of spells.
每次修改后,输出 Polycarp 使用当前法术集合所能造成的最大伤害。
输入输出样例
输入#1
6 1 5 0 10 1 -5 0 5 1 11 0 -10
输出#1
5 25 10 15 36 21
输入解题思路,AI测评打分。不知道怎么写?