CF1217B.Zmei Gorynich

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!

Initially Zmei Gorynich has xx heads. You can deal nn types of blows. If you deal a blow of the ii-th type, you decrease the number of Gorynich's heads by min(di,curX)min(d_i, curX), there curXcurX is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows hih_i new heads. If curX=0curX = 0 then Gorynich is defeated.

You can deal each blow any number of times, in any order.

For example, if curX=10curX = 10, d=7d = 7, h=10h = 10 then the number of heads changes to 1313 (you cut 77 heads off, but then Zmei grows 1010 new ones), but if curX=10curX = 10, d=11d = 11, h=100h = 100 then number of heads changes to 00 and Zmei Gorynich is considered defeated.

Calculate the minimum number of blows to defeat Zmei Gorynich!

You have to answer tt independent queries.

你正在与兹梅·戈雷尼奇(Zmei Gorynich)战斗——一位源自斯拉夫神话的凶猛怪物,形似巨龙的多头爬行动物!

初始时,兹梅·戈雷尼奇有 xx 个头。你可以施展 nn 种不同类型的攻击。若你施展第 ii 种攻击,则会减少兹梅·戈雷尼奇当前头数 curXcurX 中的 min⁡(di,curX)\min(d_i, curX) 个头;但若此次攻击后兹梅·戈雷尼奇仍至少剩下一个头,他便会再生 hih_i 个新头。若 curX=0curX = 0,则兹梅·戈雷尼奇被击败。

每种攻击均可使用任意多次,且顺序不限。

例如,若 curX=10curX = 10,d=7d = 7,h=10h = 10,则头数变为 1313(你砍掉 77 个头,但兹梅又长出 1010 个新头);而若 curX=10curX = 10,d=11d = 11,h=100h = 100,则头数变为 00,兹梅·戈雷尼奇即被击败。

请计算击败兹梅·戈雷尼奇所需的最少攻击次数!

你需要回答 tt 个相互独立的查询。

输入格式

The first line contains one integer tt (1≤t≤1001 \le t \le 100) – the number of queries.

The first line of each query contains two integers nn and xx (1≤n≤1001 \le n \le 100, 1≤x≤1091 \le x \le 10^9) — the number of possible types of blows and the number of heads Zmei initially has, respectively.

The following nn lines of each query contain the descriptions of types of blows you can deal. The ii-th line contains two integers did_i and hih_i (1≤di,hi≤1091 \le d_i, h_i \le 10^9) — the description of the ii-th blow.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示查询次数。

每次查询的第一行包含两个整数 nn 和 xx(1≤n≤1001 \le n \le 100,1≤x≤1091 \le x \le 10^9),分别表示可使用的打击类型数量以及泽梅(Zmei)初始的头数。

每次查询接下来的 nn 行描述了你可以使用的各种打击类型。其中第 ii 行包含两个整数 did_i 和 hih_i(1≤di,hi≤1091 \le d_i, h_i \le 10^9),表示第 ii 种打击的描述。

输出格式

For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich.

If Zmei Gorynuch cannot be defeated print −1-1.

对于每个查询,请输出击败兹梅·戈雷内奇所需的最少攻击次数。

如果无法击败兹梅·戈雷内奇,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    3 10
    6 3
    8 2
    1 4
    4 10
    4 1
    3 2
    2 6
    1 100
    2 15
    10 11
    14 100

    输出#1

    2
    3
    -1

说明/提示

In the first query you can deal the first blow (after that the number of heads changes to 10−6+3=710 - 6 + 3 = 7), and then deal the second blow.

In the second query you just deal the first blow three times, and Zmei is defeated.

In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting?

在第一次查询中,你可以先发动第一次攻击(之后头的数量变为 10−6+3=710 - 6 + 3 = 7),然后再发动第二次攻击。

在第二次查询中,你只需连续发动三次第一次攻击,即可击败兹梅·戈雷内奇。

在第三次查询中,你无法击败兹梅·戈雷内奇。也许说服它停止战斗会更好?

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

首页