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. 转gif图

    用QQ影音截取影片 + Ulead GIF Animator510编辑.

  2. easyUI datagrid表格添加“暂无记录”显示

    扩展grid的onAfterRender事件 var myview = $.extend({}, $.fn.datagrid.defaults.view, {     onAfterRender: f ...

  3. 【知识结构】最强Thymeleaf知识体系

    在开发一个小项目的时候,使用的是Spring Boot,Spring Boot 官方推荐的前端模板是thymeleaf, 花了两天时间将官方的文档看完并总结了下知识体系结构.转载请注明出处,https ...

  4. Mycat之日志分析跨分片事务以及存储过程的执行过程

    1 针对成功事务: 过程说明: 1.初始化连接,路由到各个分片 2.开启非阻塞执行更新,然后执行时候每个节点执行2次 3.执行提交,各节点返回commit 4.释放连接,先释放datasource然后 ...

  5. eclipse+minGW 调试ffmpeg错误:No symbol table is loaded. Use the "file" command.

    转载地址:http://www.blogjava.net/fancydeepin/archive/2012/11/19/391520.html 数据结构第二篇:  eclipse SDK 安装和配置 ...

  6. linux 修改openfiles

    使用ulimit -a 可以查看当前系统的所有限制值,使用ulimit -n 可以查看当前的最大打开文件数. 新装的linux默认只有1024,当作负载较大的服务器时,很容易遇到error: too ...

  7. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 8_Neural Networks Representation 神经网络的表述

    神经网络是一种受大脑工作原理启发的模式. 它在许多应用中广泛使用:当您的手机解释并理解您的语音命令时,很可能是神经网络正在帮助理解您的语音; 当您兑现支票时,自动读取数字的机器也使用神经网络. 8.1 ...

  8. 证明3|n(n+1)(2n+1)

    [证明3|n(n+1)(2n+1)] n(n+1)(2n+1) => n(n+1)(n+2+n-1) => n(n+1)(n+2) + n(n+1)(n-1) 因为n(n+1)(n+2). ...

  9. resin3.X那些事之resin.conf

    [经验总结]resin那些事之resin.conf ----by johnson 话说与resin打交道很久了,却从未系统了解过.resin一听火了,说:你老兄当真与我打交道很久了?工具.流程如此发达 ...

  10. oracle级联更新与级联删除

    Oracle级联删除:可以使用外键约束来实现,建立表的主外键关系,给列设置级联删除.如下: ——创建了CLASS表,并设置ID字段为主键. -- Create tablecreate table CL ...