#G. F - Ignore Operations

    传统题 1000ms 256MiB

F - Ignore Operations

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

F - Ignore Operations

Score : $500$ points

Problem Statement

Takahashi has an integer $x$. Initially, $x = 0$.

There are $N$ operations. The $i$-th operation $(1 \leq i \leq N)$ is represented by two integers $t_i$ and $y_i$ as follows:

  • If $t_i = 1$, replace $x$ with $y_i$.
  • If $t_i = 2$, replace $x$ with $x + y_i$.

Takahashi may skip any number between $0$ and $K$ (inclusive) of the operations. When he performs the remaining operations once each without changing the order, find the maximum possible final value of $x$.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $0 \leq K \leq N$
  • $t_i \in \{1,2\} \, (1 \leq i \leq N)$
  • $|y_i| \leq 10^9 \, (1 \leq i \leq N)$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

t1t_1 y1y_1

\vdots

tNt_N yNy_N

Output

Print the answer.


5 1
2 4
2 -3
1 2
2 1
2 -3
3

If he skips the $5$-th operation, $x$ changes as $0 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3$, so $x$ results in $3$. This is the maximum.


1 0
2 -1000000000
-1000000000

10 3
2 3
2 -1
1 4
2 -1
2 5
2 -9
2 2
1 -6
2 5
2 -3
15

2024暑假入门组刷题营第三期(十一)

未参加
状态
已结束
规则
IOI
题目
8
开始于
2024-7-19 13:00
结束于
2024-7-19 15:00
持续时间
2 小时
主持人
参赛人数
9