x heads. You can deal n "> ntypes of blows. If you deal a blow of the i "> i -th" />

当前位置 : 主页 > 手机开发 > ROM >

CF1217B Zmei Gorynich

来源:互联网 收集:自由互联 发布时间:2021-06-10
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads! Initially Zmei Gorynich has x "> x heads. You can deal n "> ntypes of blows. If you deal a blow of the i "> i -th

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

分享图片

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

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

For example, if curX=10d=7,h=10 then the number of heads changes to 13 (you cut 7 heads off, but then Zmei grows 10 new ones), but if curX=10d=11, h=100 then number of heads changes to 0 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 t (1t100) – the number of queries.

The first line of each query contains two integers nn and x (1n1001x10^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 d_i and h_i (1d_i,h_i109) — the description of the i-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.

Example input
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
2
3
-1
Note

In the first query you can deal the first blow (after that the number of heads changes to 106+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?

先解释下题意,给定T组数据,每组数据第一行输入两个整数n和x,接下来n行每行输入两个整数d-i和h_i。分别是一回合能造成的damage和造成伤害后怪物回复的hp,怪物总hp是x点。

思路是贪心,先选出一个最大的max_d_i判断与x的关系,在对d_i-h_i排个序,<0则一定有解。

下面给出代码

分享图片
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ss
{
    long long a;
    long long b;
}e[505];
inline bool cmp(const ss&A,const ss&B)
{
    return A.a>B.a;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;++i)
    {
        ll n,m;
        cin>>n>>m;
        ll mmax=1;
        for(int j=0;j<n;++j)
        {
            long long x,y;
            cin>>x>>y;
            e[j].a=x-y;
            e[j].b=x;
            mmax=max(mmax,x);
        }
        sort(e,e+n,cmp);
        m-=mmax;
        if(m<=0)
        {
            cout<<1<<endl;continue;
        }
        if(e[0].a>0)
        {
            int tt=m/e[0].a+2;
            if(m%e[0].a==0)
            {
                tt--;
            }
            cout<<tt<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }
    return 0;
}
View Code

做这题时混用了scanf和cin,为了加速关闭了文件流同步,最后就疯狂RE,切忌偷懒啊。

网友评论