#P16765. [GKS 2020 #E] Toys
[GKS 2020 #E] Toys
Problem Description
Little Axel has toys numbered from to . Each toy has properties:
- —enjoyment, which is the number of minutes Axel can play with toy number without getting bored with it;
- —remembrance, which is the number of minutes it takes Axel to forget toy number after having played with it.
The toys are arranged in a circle, from to clockwise. Axel plays with them one by one.
When Axel reaches toy which he has not played with yet, or which he has already forgotten about, he plays with it for minutes and then immediately moves to the next one (clockwise).
If he reaches a toy that he has not forgotten yet (if less than minutes have passed since the last time he finished playing with it), he will stop and cry.
We can define the time Axel spent playing as the sum of of every toy Axel played with before stopping. If Axel played with a toy several times, it should be counted that many times.
Given the description of the toys, remove the smallest possible number of them in order to make Axel play either an indefinitely long time, or (if that is not possible) as long as possible before he stops.
Note:
- Axel has never played with these toys before;
- he cannot be left without toys;
- he always starts with the toy that has the smallest number;
- after finishing playing with the toy that has the largest number, he will move to the toy that has the smallest number.
Input Format
The first line of the input gives the number of test cases, . test cases follow. Each test case begins with a line containing the integer . Next lines contain integers each: and . The -th line is describing the toy number .
Output Format
For each test case, output one line containing Case #x: y z, where:
- is the test case number (starting from );
- is the longest time Axel will play in minutes or
INDEFINITELY(without quotes) if he will play indefinitely long time. - is the minimal number of toys to remove so that Axel could play with the rest of them either indefinitely or as long as possible;
4
1
5 1
2
5 10
10 3
3
30 17
5 10
10 3
3
5 10
5 10
5 11
Case #1: 5 0
Case #2: INDEFINITELY 0
Case #3: INDEFINITELY 1
Case #4: 25 0
Hint
In Sample Case # there is only toy, so Axel will play with it and will get bored in minutes.
In Sample Case #, after playing with the toy number for minutes, he will need to not play with it for minutes, which he will spend playing with the toy number . After that he will return to the toy number and play with it for minutes, during which he will forget the toy number , and so on. Thus he will play for an indefinitely long time.
In Sample Case #, although Axel can play with the toy number for minutes, if we remove it he will be able to play with the others indefinitely. So we remove it, and keep the other two.
In Sample Case #, Axel will play with the toys in the following order: , , , , , and then he will stop and cry as he still remembers the toy number . So, in total he will play for minutes.
Limits
.
.
.
Test Set
.
Test Set
.