Wake up... I have to code...
Time limit2sMemory limit512 MB
Given N alarms that ring at T, T+K, T+2K, ..., pick two so their union of ring times up to D is largest, breaking ties lexicographically.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Brute force, Hash map
- Solved
- No attempts yet
Problem
Geonmo codes until dawn every day and goes to work early in the morning. To set an alarm quickly and get some sleep, he plans to turn on only two alarms. But in case he does not hear them, he wants to turn on the two alarms that can ring the most times by the time he has to wake up. Let us pick the alarms that Geonmo should turn on.
The alarm Geonmo uses has a snooze button. The snooze button turns off a ringing alarm and makes it ring again after a short while.
Geonmo presses the snooze button as soon as every alarm rings, until the time he has to wake up. If he keeps pressing snooze, two alarms sometimes ring at the same time. In that case the two alarms ring as one, and pressing the snooze button for either of them acts as if the snooze button were pressed for both alarms.
For example, suppose the list of alarms he can turn on is given as follows. The snooze time is the time from pressing the snooze button until the alarm rings again.
If the time Geonmo has to wake up is , he can hear the alarms as follows.
If he turns on alarms 1 and 3, the alarms ring twenty times as follows. An alarm ringing at times (6, 12, 18, 24, 30) is counted as ringing only once.

Each position with a red dot is a time the alarm rings.
He may choose other alarms, but no choice rings as many times or more.
Input
The first line gives two integers, the number of alarms and the time Geonmo has to wake up , separated by a space. ,
From the second line, the -th of lines gives the start time of the alarm and the snooze time , separated by a space. ,
All values in the input are integers, and for every , is guaranteed to be a multiple of .
Output
On the first line, print the two alarm numbers Geonmo should turn on in increasing order, separated by a space.
If there are several answers, print the lexicographically smallest one.
On the second line, print the number of times the alarms ring.