CF1455G.Forbidden Value

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp is editing a complicated computer program. First, variable xx is declared and assigned to 00. Then there are instructions of two types:

  1. set yy vv — assign xx a value yy or spend vv burles to remove that instruction (thus, not reassign xx);
  2. if yy …\dots end block — execute instructions inside the if block if the value of xx is yy and ignore the block otherwise.

if blocks can contain set instructions and other if blocks inside them.

However, when the value of xx gets assigned to ss, the computer breaks and immediately catches fire. Polycarp wants to prevent that from happening and spend as few burles as possible.

What is the minimum amount of burles he can spend on removing set instructions to never assign xx to ss?

Polycarp 正在编辑一个复杂的计算机程序。首先,声明变量 xx 并将其赋值为 00。随后,程序中包含两类指令:

  1. set $y$ $v$ —— 将 xx 赋值为 yy;或者花费 vv burles 删除该指令(从而不改变 xx 的值);
  2. if $y$ $\dots$ end block —— 若 xx 的当前值等于 yy,则执行 if 块内的所有指令;否则忽略整个 if 块。

if 块内部可以包含 set 指令以及其他嵌套的 if 块。

然而,一旦 xx 被赋值为 ss,计算机便会立即崩溃并起火。Polycarp 希望避免这一情况发生,并且希望花费尽可能少的 burles。

请问:为确保 xx 永远不会被赋值为 ss,他最少需要花费多少 burles 来删除 set 指令?

输入格式

The first line contains two integers nn and ss (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤s≤2⋅1051 \le s \le 2 \cdot 10^5) — the number of lines in the program and the forbidden value of xx.

The following nn lines describe the program. Each line is one of three types:

  1. set yy vv (0≤y≤2⋅105,1≤v≤109)(0 \le y \le 2 \cdot 10^5, 1 \le v \le 10^9);
  2. if yy (0≤y≤2⋅105)(0 \le y \le 2 \cdot 10^5);
  3. end.

Each if instruction is matched by an end instruction. Each end instruction has an if instruction to match.

第一行包含两个整数 nn 和 ss(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤s≤2⋅1051 \le s \le 2 \cdot 10^5)—— 分别表示程序的行数和 xx 的禁止取值。

接下来的 nn 行描述该程序。每行属于以下三种类型之一:

  1. set $y$ $v$(其中 0≤y≤2⋅1050 \le y \le 2 \cdot 10^5,1≤v≤1091 \le v \le 10^9);
  2. if $y$(其中 0≤y≤2⋅1050 \le y \le 2 \cdot 10^5);
  3. end。

每个 if 指令都恰好匹配一个 end 指令,且每个 end 指令也恰好匹配一个 if 指令。

输出格式

Print a single integer — the minimum amount of burles Polycarp can spend on removing set instructions to never assign xx to ss.

输出一个整数——Polycarp 为移除若干赋值指令,使得变量 xx 永远不会被赋值给 ss 所需花费的最少 burles 数。

输入输出样例

  • 输入#1

    5 1
    set 1 10
    set 2 15
    if 2
    set 1 7
    end

    输出#1

    17
  • 输入#2

    7 2
    set 3 4
    if 3
    set 10 4
    set 2 7
    set 10 1
    end
    set 4 2

    输出#2

    4
  • 输入#3

    9 200
    if 0
    set 5 5
    if 5
    set 100 13
    end
    if 100
    set 200 1
    end
    end

    输出#3

    1
  • 输入#4

    1 10
    set 1 15

    输出#4

    0

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

首页