题库练习 For Gamers. By Gamers.
← 上一题 下一题 →

A14885 | For Gamers. By Gamers.

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $C$ coins to spend on his squad.

Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $C$ coins.

There are $n$ types of units. Every unit type has three parameters:

- $c_i$ — the cost of recruiting one unit of the $i$ -th type;
- $d_i$ — the damage that one unit of the $i$ -th type deals in a second;
- $h_i$ — the amount of health of one unit of the $i$ -th type.

Monocarp has to face $m$ monsters. Every monster has two parameters:

- $D_j$ — the damage that the $j$ -th monster deals in a second;
- $H_j$ — the amount of health the $j$ -th monster has.

Monocarp has to fight only the $j$ -th monster during the $j$ -th battle. He wants all his recruited units to stay alive. Both Monocarp's squad and the monster attack continuously (not once per second) and at the same time. Thus, Monocarp wins the battle if and only if his squad kills the monster strictly faster than the monster kills one of his units. The time is compared with no rounding.

For each monster, Monocarp wants to know the minimum amount of coins he has to spend to kill that monster. If this amount is greater than $C$ , then report that it's impossible to kill that monster.

输入格式

The first line contains two integers $n$ and $C$ ( $1 \le n \le 3 \cdot 10^5$ ; $1 \le C \le 10^6$ ) — the number of types of units and the amount of coins Monocarp has before each battle.

The $i$ -th of the next $n$ lines contains three integers $c_i, d_i$ and $h_i$ ( $1 \le c_i \le C$ ; $1 \le d_i, h_i \le 10^6$ ).

The next line contains a single integer $m$ ( $1 \le m \le 3 \cdot 10^5$ ) — the number of monsters that Monocarp has to face.

The $j$ -th of the next $m$ lines contains two integers $D_j$ and $H_j$ ( $1 \le D_j \le 10^6$ ; $1 \le H_j \le 10^{12}$ ).

输出格式

Print $m$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $C$ , then print $-1$ .

输入输出样例

输入 #1
3 10
3 4 6
5 5 5
10 3 4
3
8 3
5 4
10 15
输出 #1
5 3 -1
输入 #2
5 15
14 10 3
9 2 2
10 4 3
7 3 5
4 3 1
6
11 2
1 1
4 7
2 1
1 14
3 3
输出 #2
14 4 14 4 7 7
输入 #3
5 13
13 1 9
6 4 5
12 18 4
9 13 2
5 4 5
2
16 3
6 2
输出 #3
12 5
C++ 编辑器
输入
输出