A. Serval and Bus
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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≤1001≤n≤100 , 1≤t≤1051≤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≤1051≤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

 
2 2
6 4
9 5
Output

 
1
Input

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

 
3
Input

 
3 7
2 2
2 3
2 4
Output

 
1
Note

In the first example, the first bus of the first route arrives at time 66 , 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 55 , so it is the answer.

In the third example, buses of the first route come at times 22 , 44 , 66 , 88 , and so fourth, buses of the second route come at times 22 , 55 , 88 , and so fourth and buses of the third route come at times 22 , 66 , 1010 , and so on, so 11 and 22 are both acceptable answers while 33 is not.

解题思路:这道题就是给你n个数据,小孩到达车站的时间;以及数据车第一次到车站的时间以及之后每个t时间就会再来一班,问你小孩会上哪辆车,如果有多辆符合,则任意输出一辆;

我们暴力算,面向数据编程;

我们先判断车第一次到能不能符合条件,不能的话再不断去加后面的时间,直到符合条件

代码如下:

 #include<iostream>
using namespace std; int n ;
int chil;
struct buss{
int first;
int t;
}bus[];
int flag = ;
int tot[];
int main()
{
cin>>n;
cin>>chil;
for(int i = ; i <= n ;i++)
{
cin>>bus[i].first>>bus[i].t;
}
for(int i = ; i <= n ;i++)
{
tot[i] += bus[i].first;
if(tot[i]<chil) //先看车第一次来是否符合条件,不符合条件则不断加
{
while()
{
tot[i] +=bus[i].t;
if(tot[i]>=chil)
break;
}
}
}
int min = 0x3f3f3f3f;
int num;
for(int i = ; i<= n ;i++)
{
if(tot[i]-chil<min) //找最接近小孩时间的车
{
min = tot[i]-chil;
num = i ;
} } cout<<num;
}

Codeforces Round #551 (Div. 2)A. Serval and Bus的更多相关文章

  1. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...

  2. Codeforces Round #551 (Div. 2)B. Serval and Toy Bricks

    B. Serval and Toy Bricks time limit per test 1 second memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)

    题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...

  4. Codeforces Round #551 (Div. 2) E. Serval and Snake (交互题)

    人生第一次交互题ac! 其实比较水 容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数:否则是偶数. 所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点. ...

  5. Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)

    yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE ...

  6. 【Codeforces】Codeforces Round #551 (Div. 2)

    Codeforces Round #551 (Div. 2) 算是放弃颓废决定好好打比赛好好刷题的开始吧 A. Serval and Bus 处理每个巴士最早到站且大于t的时间 #include &l ...

  7. Codeforces Round #551 (Div. 2) A-E

    A. Serval and Bus 算出每辆车会在什么时候上车, 取min即可 #include<cstdio> #include<algorithm> #include< ...

  8. Codeforces Round #551 (Div. 2) A~E题解

    突然发现上一场没有写,那就补补吧 本来这场应该5题的,结果一念之差E fail了 A. Serval and Bus 基本数学不解释,假如你没有+1 -1真的不好意思见人了 #include<c ...

  9. C. Serval and Parenthesis Sequence 【括号匹配】 Codeforces Round #551 (Div. 2)

    冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit pe ...

随机推荐

  1. PHP文件操作(三)-文件的写入

    fwrite()  //对文件进行写入 fwrite(file,string,length)file:必选项,需要写入的文件string:必选项,规定要写入文件的字符串length:可选项,规定要写入 ...

  2. HALCON 算子函数(四) File

    HALCON 算子函数——Chapter 4 : File 4.1 Images 1. read_image 功能:读取有不同文件格式的图像. 2. read_sequence 功能:读取图像. 3. ...

  3. Python基本数据类型--列表、元组、字典、集合

    一.Python基本数据类型--列表(List) 1.定义:[ ]内以逗号分隔,按照索引,存放各种数据类型,每个位置代表一个元素. 2.列表的创建: # 方式一 list1 = ['name','ag ...

  4. Dom对象与jQuery对象的转换

  5. Basics

    [Basics] 1.You can declare multiple constants or multiple variables on a single line, separated by c ...

  6. MyBatis之 逆向工程生成代码

    逆向工程: 所谓mybatis逆向工程,就是mybatis会根据我们设计好的数据表,自动生成pojo.mapper以及mapper.xml. 工程简单案例: 1,新建一个java项目,把需要使用的ja ...

  7. 04.webservice客户端调用

    不要求所有的元素都理解,真正做开发的时候,有一些必须是要用的. 以后我们做开发的时候服务访问点的集合就一个服务的访问点.服务访问点绑定了具体的一个服务类,绑定的这个东西它本身也是一个元素.往上找,四个 ...

  8. 在centos 下安装配置基于gitosis 的git 服务

    前言 这里我用的系统是centos 6.2, 在服务器上的准备工作(服务器IP为10.0.2.8 ): 1.安装 openssh服务器与客户端工具 $ sudo yum install openssh ...

  9. laravel 验证表单信息

    1控制器验证 $this->validate($request,[ 'Student.name'=>'required|min:2|max:20', 'Student.age'=>' ...

  10. SQL Server 触发器触发器

    内容摘抄自http://www.cnblogs.com/hoojo/archive/2011/07/20/2111316.html,只供自己笔记使用 触发器是一种特殊类型的存储过程,它不同于之前的我们 ...