CF625E.Frog Fights

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ostap Bender recently visited frog farm and was inspired to create his own frog game.

Number of frogs are places on a cyclic gameboard, divided into mm cells. Cells are numbered from 11 to mm , but the board is cyclic, so cell number 11 goes right after the cell number mm in the direction of movement. ii -th frog during its turn can jump for aia_{i} cells.

Frogs move in turns, game starts with a move by frog 11 . On its turn ii -th frog moves aia_{i} cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the ii -th frog, that frog is also knocked out. After this the value aia_{i} is decreased by the number of frogs that were knocked out during this turn. If aia_{i} is zero or goes negative, then ii -th frog doesn't make moves anymore.

After frog number 11 finishes its turn, frog number 22 starts to move, then frog number 33 and so on. After the frog number nn makes its move, frog 11 starts to move again, then frog 22 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.

Help Ostap to identify, what frogs will stay on the board at the end of a game?

输入格式

First line of the input contains two integers nn and mm ( 1<=n<=100000,1<=m<=109,n<=m1<=n<=100000,1<=m<=10^{9},n<=m ) — number of frogs and gameboard size, respectively.

Following nn lines contains frogs descriptions — two integers pip_{i} and aia_{i} ( 1<=pi,ai<=m1<=p_{i},a_{i}<=m ) — the number of cell occupied by ii -th frog initially and initial jump length. All pip_{i} are guaranteed to be distinct.

输出格式

In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.

输入输出样例

  • 输入#1

    3 5
    2 1
    5 3
    4 3
    

    输出#1

    1
    3 
  • 输入#2

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

    输出#2

    2
    1 4 

说明/提示

In the first sample first frog jumps 11 cell and finishes in cell number 33 . Second frog jumps for 33 cells and finishes on cell number 33 , knocking out frog number 11 . Current jump length for frog number 22 is now 22 . Third frog jumps to cell 22 , then second frog jumps to cell 55 . Third frog in turn finishes in cell 55 and removes frog 22 from the gameboard. Now, it's the only remaining frog in the game.

In the second sample first frog jumps 22 cells and knocks out frogs in cells 22 and 33 . Its value aia_{i} is now 00 . Then fourth frog jumps and knocks out fifth frog and its aia_{i} is now 00 too. These two frogs will remains on the gameboard forever.

首页