#P16765. [GKS 2020 #E] Toys

[GKS 2020 #E] Toys

Problem Description

Little Axel has NN toys numbered from 11 to NN. Each toy has 22 properties:

  • EiE_i—enjoyment, which is the number of minutes Axel can play with toy number ii without getting bored with it;
  • RiR_i—remembrance, which is the number of minutes it takes Axel to forget toy number ii after having played with it.

The toys are arranged in a circle, from 11 to NN clockwise. Axel plays with them one by one.

When Axel reaches toy ii which he has not played with yet, or which he has already forgotten about, he plays with it for EiE_i minutes and then immediately moves to the next one (clockwise).

If he reaches a toy that he has not forgotten yet (if less than RiR_i 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 EiE_i 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, TT. TT test cases follow. Each test case begins with a line containing the integer NN. Next NN lines contain 22 integers each: EiE_i and RiR_i. The ii-th line is describing the toy number ii.

Output Format

For each test case, output one line containing Case #x: y z, where:

  • xx is the test case number (starting from 11);
  • yy is the longest time Axel will play in minutes or INDEFINITELY (without quotes) if he will play indefinitely long time.
  • zz 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 #11 there is only 11 toy, so Axel will play with it and will get bored in 55 minutes.

In Sample Case #22, after playing with the toy number 11 for 55 minutes, he will need to not play with it for 1010 minutes, which he will spend playing with the toy number 22. After that he will return to the toy number 11 and play with it for 55 minutes, during which he will forget the toy number 22, and so on. Thus he will play for an indefinitely long time.

In Sample Case #33, although Axel can play with the toy number 11 for 3030 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 #44, Axel will play with the toys in the following order: 11, 22, 33, 11, 22, and then he will stop and cry as he still remembers the toy number 33. So, in total he will play for 2525 minutes.

Limits

1T1001 \le T \le 100.

1Ei1091 \le E_i \le 10^9.

1Ri1091 \le R_i \le 10^9.

Test Set 11

1N121 \le N \le 12.

Test Set 22

1N1051 \le N \le 10^5.