CF1657D.For Gamers. By Gamers.

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

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.

Monocarp 正在玩一款策略游戏。在游戏中,他招募一支小队来对抗怪物。每次战斗前,Monocarp 有 CC 枚金币可用于组建小队。

每次战斗开始前,他的小队为空。Monocarp 选择一种单位类型,并招募该类型的单位,数量不超过用 CC 枚金币所能招募的最大数量。

共有 nn 种单位类型。每种单位类型具有三个参数:

  • cic_i —— 招募一个第 ii 类单位所需的金币数;
  • did_i —— 一个第 ii 类单位每秒造成的伤害;
  • hih_i —— 一个第 ii 类单位的生命值。

Monocarp 需要面对 mm 只怪物。每只怪物具有两个参数:

  • DjD_j —— 第 jj 只怪物每秒造成的伤害;
  • HjH_j —— 第 jj 只怪物的生命值。

Monocarp 在第 jj 场战斗中仅需对抗第 jj 只怪物。他希望所有已招募的单位均存活至战斗结束。Monocarp 的小队与怪物持续(而非每秒一次)且同时进行攻击。因此,Monocarp 获胜当且仅当他所招募的小队击杀怪物所用的时间严格小于怪物击杀其任意一个单位所用的时间。时间比较不作任何舍入处理。

对于每只怪物,Monocarp 想知道击杀该怪物所需的最少金币数。若该金币数大于 CC,则报告无法击杀该怪物。

输入格式

The first line contains two integers nn and CC (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5; 1≤C≤1061 \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 (1≤ci≤C1 \le c_i \le C; 1≤di,hi≤1061 \le d_i, h_i \le 10^6).

The next line contains a single integer mm (1≤m≤3⋅1051 \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 (1≤Dj≤1061 \le D_j \le 10^6; 1≤Hj≤10121 \le H_j \le 10^{12}).

第一行包含两个整数 nn 和 CC(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5;1≤C≤1061 \le C \le 10^6)—— 分别表示单位种类数以及 Monocarp 每场战斗前拥有的金币数量。

接下来的 nn 行中,第 ii 行包含三个整数 ci,dic_i, d_i 和 hih_i(1≤ci≤C1 \le c_i \le C;1≤di,hi≤1061 \le d_i, h_i \le 10^6)。

下一行包含一个整数 mm(1≤m≤3⋅1051 \le m \le 3 \cdot 10^5)—— 表示 Monocarp 需要面对的怪物数量。

接下来的 mm 行中,第 jj 行包含两个整数 DjD_j 和 HjH_j(1≤Dj≤1061 \le D_j \le 10^6;1≤Hj≤10121 \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.

输出 mm 个整数。对于每个怪物,输出 Monocarp 杀死该怪物所需的最少金币数量。若该数量大于 CC,则输出 −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.

考虑第一个样例中的第一只怪物。

Monocarp 无法招募一个第一类单位,因为这将导致他与该怪物在 0.750.75 秒内互相击杀。他可以花费 66 枚金币招募两个第一类单位,并在 0.3750.375 秒内击杀该怪物。

Monocarp 可以招募一个第二类单位,因为他能在 0.60.6 秒内击杀该怪物,而该怪物需要 0.6250.625 秒才能击杀他——该单位更快。因此,55 枚金币即足够。

Monocarp 至少需要三个第三类单位才能击杀第一只怪物,这将花费 3030 枚金币。

若 Monocarp 选择第二类单位并招募其中的一个,则花费的金币最少。

输入解题思路,AI测评打分。不知道怎么写?

首页