A. Serval and Bus

                                                                             A. Serval and Bus

It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.

Serval will go to the bus station at time tt, and there are nn bus routes which stop at this station. For the ii-th bus route, the first bus arrives at time sisi minutes, and each bus of this route comes didi minutes later than the previous one.

As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

Input

The first line contains two space-separated integers nn and tt (1≤n≤100, 1≤t≤105) — the number of bus routes and the time Serval goes to the station.

Each of the next nn lines contains two space-separated integers sisi and didi (1≤si,di≤105) — the time when the first bus of this route arrives and the interval between two buses of this route.

Output

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

Examples

input

Copy

2 2
6 4
9 5

output

Copy

1

input

Copy

5 5
3 3
2 5
5 6
4 9
6 1

output

Copy

3

input

Copy

3 7
2 2
2 3
2 4

output

Copy

1

Note

In the first example, the first bus of the first route arrives at time 6, and the first bus of the second route arrives at time 99, so the first route is the answer.

In the second example, a bus of the third route arrives at time 5, so it is the answer.

In the third example, buses of the first route come at times 2, 4, 6, 8, and so fourth, buses of the second route come at times 2, 5, 8, and so fourth and buses of the third route come at times 2, 6, 10, and so on, so 1 and 2are both acceptable answers while 3 is not.

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std ;
const int MAX = 10005 ;
struct node {
	int s ;
	int d ;
	int index ;
};
node a[MAX ] ;
bool cmp(const node &a , const node &b){
	return a.s < b.s ;
}
int main(){
	int n ,t ;
	int pos =0;
	cin >>n >>t ;
	for(int i = 1 ; i<=n ;i ++ ) {
		cin >> a[i].s >> a[i].d ;
		a[i].index = i ;
	}
	sort(a+1,a+1+n,cmp);
	int minn = 0x3f3f3f3f ;
	for(int i = 1 ; i<=n ; i++ ){
		if(a[i].s == t ){
			pos = a[i].index ;
			break ;
		}
		while(a[i].s <t ){
			a[i].s+=a[i].d ;
		}
		if(minn > a[i].s -t){
			pos = a[i].index ;
			minn = a[i].s -t ;
		}
	
	}
	cout<<pos ;
	return 0 ;
}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值