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. Android BindService中遇到的一个小问题

    今天在使用BindService的时候遇到个小问题,我希望通过Bindservice获取到这个服务,然后执行服务内的某个自定义方法,如下: if(bindService==null){ Intent ...

  2. Py修行路 python基础 (十三)匿名函数 与 内置函数

    一.匿名函数  1.定义: 匿名函数顾名思义就是指:是指一类无需定义标识符(函数名)的函数或子程序. 2.语法格式:lambda 参数:表达式 lambda语句中,开头先写关键字lambda,冒号前是 ...

  3. Venom的简单使用

    工具地址:https://github.com/r00t-3xp10it/venom 打开到venom目录,输入./venom.sh 打开程序 按回车键继续 这里有很多的模块,要用哪个模块就输入它的编 ...

  4. 实验吧CTF题库-隐写术(部分)

    Spamcarver 用kali下载图片 root@sch01ar:~# wget http://ctf5.shiyanbar.com/stega/spamcarver/spamcarver.jpg ...

  5. rpm --import /etc/pki/rpm-gpg/RPM* 有什么用?

      今天用yum安装软件,遇到了Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL问题,为了加深印象,特别搜索了RPM-GPG-K ...

  6. DataTable改变column类型

    1.必须先克隆DataTable 2.列换类型 3.逐行往新DataTable赋值,并转换某列类型 如: DataTable dt = diorg.Clone(); //必须先克隆,此时并不包含数据 ...

  7. 解决free -h cached 过大 问题

    //先同步数据 sync //cache 释放: //To free pagecache: echo 1 > /proc/sys/vm/drop_caches //To free dentrie ...

  8. 进程间通信___命名管道(FIFO)

    命名管道(FIFO) 基本概念 命名管道和一般的管道基本相同,但也有一些显著的不同: 命名管道是在文件系统中作为一个特殊的设备文件而存在的. 不同祖先的进程之间可以通过管道共享数据. 当共享管道的进程 ...

  9. Java两大测试方法Junit和TestNG的比较

    开发过程中,经常会用到JAVA测试,前端javas cript的调试相对比较轻松,firebug,console.log()等,但是java的就比较纠结点,每次改完都要去编译再运行,过程相对缓慢,加上 ...

  10. c# 下实现ping 命令操作

    1>通过.net提供的类实现 using System; using System.Collections.Generic; using System.Linq; using System.Te ...