Educational Codeforces Round 72 (Rated for Div. 2)--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 $$$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(d_i, 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 = 10$$$, $$$d = 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 = 10$$$, $$$d = 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 $$$t$$$ independent queries.

Input

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

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

The following $$$n$$$ lines of each query contain the descriptions of types of blows you can deal. The $$$i$$$-th line contains two integers $$$d_i$$$ and $$$h_i$$$ ($$$1 \le d_i, h_i \le 10^9$$$) — 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

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 = 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?

 

怪物有X滴血,每一种攻击会消灭它D,然后再增加它H。问最少多少次使得它==0。

首先特判两种情况,一种的D>=X,只需要使用一次,另一种是所有的攻击D-H<=0,一定不行-1。

然后肯定行了。

处理出最大的D,left=X-D。

对于每一种攻击,用left/每种攻击的差值,得到每一种的最小攻击数量,取最小值。

也就是先处理出left,最后使用D一招绝杀它。所以那个+1是加的最后一招绝杀。

 

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include<iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
using namespace std;
#define rep(i,a,b) for(register ll i=(a);i<=(b);i++)
#define dep(i,a,b) for(register ll i=(a);i>=(b);i--)
//priority_queue<ll,vector<ll>,less<ll> >q;
ll dx[]= {-1,1,0,0,-1,-1,1,1};
ll dy[]= {0,0,-1,1,-1,1,1,-1};
const ll maxn = 1000+66;
const ll maxm=100000+66;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
const ll INF=99999999;
struct node
{
    ll d;
    ll h;
    ll num;
    ll s;
}arr[maxn];
int main()
{
    ll t;
    scanf("%lld",&t);
    while(t--)
    {
        ll n,x;
        scanf("%lld %lld",&n,&x);
        ll maxx=-1;
        ll flag=0;
        rep(i,1,n)
        {
            scanf("%lld %lld",&arr[i].d,&arr[i].h);
            arr[i].num=0;
            arr[i].s=arr[i].d-arr[i].h;
            maxx=max(maxx,arr[i].d);
            if(arr[i].s>0)flag=1;
        }
        if(maxx>=x)
        {
            printf("1\n");
            continue;
        }
        if(!flag)
        {
            printf("-1\n");
            continue;
        }
        ll minn=inf;
        rep(i,1,n)
        {
            if(arr[i].s<=0)continue;
            ll le=-(maxx-x);
            arr[i].num=le/arr[i].s;
            if(arr[i].s*arr[i].num<le)arr[i].num++;
            minn=min(minn,arr[i].num);
        }
        printf("%lld\n",minn+1);
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值