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(di,curX), there curX is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows hi 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≤t≤100
) – the number of queries.
The first line of each query contains two integers n
and x (1≤n≤100, 1≤x≤109
) — 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 di and hi (1≤di,hi≤109) — 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?
题意:你去打怪兽,有n个魔法,第i个魔法对怪物造成ai点伤害,然后怪物恢复bi点血,怪物初始有x点血,每个魔法可以任选任意次使用,问最少使用多少次魔法
思路:
1.如果x小于等于ai中最大的数,那我直接用最大的ai打死就好了,输出1
2.不符合第一点的情况下,如果所有a[i]<=b[i],那怪物不可能被打死,输出-1
3.不符合第二点的情况下,最后一击给最大的a[i]打,其他的给最大的a[i]-b[i]打
#include
#include
#include
#include
#include
#include
using namespace std;
#define maxn 150000
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,x;
scanf("%d %d",&n,&x);
int max1=-199999999,f=0,max2=0,id=0;
for(int i=1;i<=n;i++)
{
int a,b;
scanf("%d %d",&a,&b);
max2=max(max2,a);
if(x<=a) f=1;
if(max10)
{
sum=(x-max2)/max1;
if((x-max2)%max1!=0) sum++;
printf("%d\n",sum+1);
}
else if(max1<=0)
{
printf("-1\n");
}
}
}