CF1657D.For Gamers. By Gamers.

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has CC 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 CC coins.

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

  • cic_i — the cost of recruiting one unit of the ii -th type;
  • did_i — the damage that one unit of the ii -th type deals in a second;
  • hih_i — the amount of health of one unit of the ii -th type.

Monocarp has to face mm monsters. Every monster has two parameters:

  • DjD_j — the damage that the jj -th monster deals in a second;
  • HjH_j — the amount of health the jj -th monster has.

Monocarp has to fight only the jj -th monster during the jj -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 CC , then report that it's impossible to kill that monster.

输入格式

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

The ii -th of the next nn lines contains three integers ci,dic_i, d_i and hih_i ( 1ciC1 \le c_i \le C ; 1di,hi1061 \le d_i, h_i \le 10^6 ).

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

The jj -th of the next mm lines contains two integers DjD_j and HjH_j ( 1Dj1061 \le D_j \le 10^6 ; 1Hj10121 \le H_j \le 10^{12} ).

输出格式

Print mm integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than CC , then print 1-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

说明/提示

Consider the first monster of the first example.

Monocarp can't recruit one unit of the first type, because it will take both him and the monster 0.750.75 seconds to kill each other. He can recruit two units for the cost of 66 coins and kill the monster in 0.3750.375 second.

Monocarp can recruit one unit of the second type, because he kills the monster in 0.60.6 seconds, and the monster kills him in 0.6250.625 seconds. The unit is faster. Thus, 55 coins is enough.

Monocarp will need at least three units of the third type to kill the first monster, that will cost 3030 coins.

Monocarp will spend the least coins if he chooses the second type of units and recruits one unit of that type.

首页