B. Zmei Gorynich

滴答滴答---题目链接 

B. Zmei Gorynich

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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(di,curX), there curXcurX is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows hihi 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.

Input

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

The first line of each query contains two integers nn and xx (1≤n≤1001≤n≤100, 1≤x≤1091≤x≤109) — 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 didi and hihi (1≤di,hi≤1091≤di,hi≤109) — the description of the ii-th blow.

Output

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.

Example

input

Copy

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

output

Copy

2
3
-1

Note

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?

 

#include <iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        scanf("%d%d",&n,&x);
        int l,r;
        l=r=0;
        for(int i=0; i<n; i++)
        {
            int b,h;
            scanf("%d%d",&b,&h);
            l=max(l,b);
            r=max(r,b-h);
        }
        if(l>=x)
        {
            cout<<1<<endl;
            continue;
        }
        if(r==0)
        {
            cout<<-1<<endl;
            continue;
        }
        cout<<(x-l+r-1)/r+1<<endl;

    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值