#abc314g. G - Amulets

G - Amulets

Score : 575575 points

问题描述

在一个洞穴中有 NN 只怪兽:怪兽1、怪兽2,……,怪兽NN。每只怪兽都有一个正整数的攻击力和一个用1到MM之间的整数表示的类型。具体来说,对于i=1,2,,Ni=1,2,\ldots,N,怪兽ii的攻击力和类型分别为AiA_iBiB_i

高桥将以生命值HH并携带一些从MM个护符中挑选出的护符(护符1、护符2,……,护符MM)进入这个洞穴冒险。

在冒险过程中,高桥按照以下步骤依次对i=1,2,,Ni=1,2,\ldots,N进行操作(只要他的生命值不降至0或以下)。

  • 如果高桥没有携带护符BiB_i,则怪兽ii会攻击他,使他的生命值减少AiA_i
  • 然后,
    • 如果他的生命值大于0,则击败怪兽ii
    • 否则,他会在未击败怪兽ii的情况下死亡,并结束冒险。

对于每个K=0,1,,MK=0,1,\ldots,M独立求解以下问题。

当从MM个护符中选择KK个护符携带进入冒险时,高桥最多能击败多少只怪兽?

约束条件保证了对于i=1,2,,Mi=1,2,\ldots,M,至少存在一只类型为ii的怪兽。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN monsters in a cave: monster 11, monster 22, \ldots, monster NN. Each monster has a positive integer attack power and a type represented by an integer between 11 and MM, inclusive. Specifically, for i=1,2,,Ni = 1, 2, \ldots, N, the attack power and type of monster ii are AiA_i and BiB_i, respectively.

Takahashi will go on an adventure in this cave with a health of HH and some of the MM amulets: amulet 11, amulet 22, \ldots, amulet MM.

In the adventure, Takahashi performs the following steps for i=1,2,,Ni = 1, 2, \ldots, N in this order (as long as his health does not drop to 00 or below).

  • If Takahashi has not brought amulet BiB_i with him, monster ii will attack him and decrease his health by AiA_i.
  • Then,
    • if his health is greater than 00, he defeats monster ii;
    • otherwise, he dies without defeating monster ii and ends his adventure.

Solve the following problem for each K=0,1,,MK = 0, 1, \ldots, M independently.

Find the maximum number of monsters that Takahashi can defeat when choosing KK of the MM amulets to bring on the adventure.

The constraints guarantee that there is at least one monster of type ii for each i=1,2,,Mi = 1, 2, \ldots, M.

Constraints

  • 1MN3×1051 \leq M \leq N \leq 3 \times 10^5
  • 1H1091 \leq H \leq 10^9
  • 1Ai1091 \leq A_i \leq 10^9
  • 1BiM1 \leq B_i \leq M
  • For each 1iM1 \leq i \leq M, there is 1jN1 \leq j \leq N such that Bj=iB_j = i.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM HH

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

For each i=0,1,2,,Mi = 0, 1, 2, \ldots, M, let XiX_i be the maximum number of monsters that Takahashi can defeat when K=iK = i. Print X0,X1,,XMX_0, X_1, \ldots, X_M separated by spaces in the following format:

X0X_0 X1X_1 \ldots XMX_M

Sample Input 1

7 3 7
3 2
1 1
4 2
1 2
5 1
9 3
2 3

Sample Output 1

2 5 7 7

Consider the case K=1K = 1. Here, Takahashi can bring amulet 22 to defeat the maximum possible number of monsters, which is 55. The adventure proceeds as follows.

  • For i=1i = 1, he avoids the attack of monster 11 since he has amulet 22. Then, he defeats monster 11.
  • For i=2i = 2, he takes the attack of monster 22 and his health becomes 66 since he does not have amulet 11. Then, he defeats monster 22.
  • For i=3i = 3, he avoids the attack of monster 33 since he has amulet 22. Then, he defeats monster 33.
  • For i=4i = 4, he avoids the attack of monster 44 since he has amulet 22. Then, he defeats monster 44.
  • For i=5i = 5, he takes the attack of monster 55 and his health becomes 11 since he does not have amulet 11. Then, he defeats monster 55.
  • For i=6i = 6, he takes the attack of monster 66 and his health becomes 8-8 since he does not have amulet 33. Then, he dies without defeating monster 66 and ends his adventure.

Similarly, when K=0K=0, he can defeat 22 monsters; when K=2K=2, he can defeat all 77 monsters by bringing amulets 22 and 33; when K=3K=3, he can defeat all 77 monsters by bringing amulets 11, 22, and 33.

Sample Input 2

15 5 400
29 5
27 4
79 1
27 2
30 3
4 1
89 2
88 3
75 5
3 1
39 4
12 1
62 4
38 2
49 1

Sample Output 2

8 12 15 15 15 15

update @ 2024/3/10 08:59:43

}