시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 512 MB | 34 | 11 | 9 | 33.333% |
Pandy is at the last stage of “Door of the Ancients”, his favorite video game. His objective is to pass through a sacred door. There are two ways to do this: By defeating a mighty guardian and snatch the key to the sacred door, or by destroying the sacred door (with brute force) directly.
Pandy has no confidence in fighting the mighty guardian, thus Pandy opts to use the second method. Pandy has N items which can be thrown to the sacred door. Each item originally has a power of Pi and a value of Vi. If Pandy throws the ith item to the sacred door, then the following will happen in order:
The same item can be thrown to the sacred door repeatedly as long as its value is not zero.
Originally, the sacred door has a durability of H. Pandy should decrease this durability to be non-positive (H ≤ 0) by throwing one or more items to destroy the sacred door.
Unfortunately, the player’s score in this game is also determined by the total value of all items belong to the player at the end of the game (that is why fighting the mighty guardian is popular among other players). Therefore, help Pandy to determine the minimum loss of the total value of all items to destroy the sacred door.
For example, let H = 100, N = 3, P1..3 = {10, 75, 50}, and V1..3 = {2, 10, 50}.
To destroy the sacred door, Pandy can throw the second item to the sacred door twice:
The total damage to the sacred door is 75 + 150 = 225, more than enough to destroy the sacred door (of original H = 100). The loss of the total value of all items is 5 + 3 = 8.
Alternatively, Pandy can throw the first item twice and the second item once:
The total damage to the sacred door is 10 + 20 + 75 = 105, and the loss of the total value of all items is 1 + 1 + 5 = 7. In this example, there is no way to destroy the sacred door with a loss of the total value of all items less than 7.
Input begins with a line containing two integers: N H (1 ≤ N ≤ 100; 1 ≤ H ≤ 109) representing the number of available items and the sacred door’s original durability, respectively. The next N lines each contains two integers: Pi Vi (1 ≤ Pi ≤ 109; 1 ≤ Vi ≤ 100) representing the original power and value of the ith item, respectively.
Output in a line an integer representing the minimum loss of the total value of all items to destroy the sacred door, or output -1 if it is not possible to destroy the sacred door.
3 100 10 2 75 10 50 50
7
This is the example from the problem description.
3 91 10 2 10 2 10 2
-1
The maximum damage Pandy can make to the sacred door by throwing all items repeatedly until they cannot be used is 10 + 20 + 10 + 20 + 10 + 20 = 90.
ICPC > Regionals > Asia Pacific > Indonesia > Indonesia National Contest > INC 2019 B번