#P6494. Pokémon Evolution Challenge

    ID: 19708 Type: Default 1000ms 256MiB

Pokémon Evolution Challenge

Pokémon Evolution Challenge

In the game Evolution! Pokémon, Mirko has ( n ) Pokémon. For the ( i)-th Pokémon, he has ( m_i ) candies. Each evolution of the ( i)-th Pokémon consumes ( k_i ) candies and gives a reward of 2 candies. Note that each Pokémon can only use its own candies for evolution.

Mirko wants to know the total number of evolutions he can perform as well as which Pokémon evolves the most times. In case of a tie, choose the one that appears earlier in the input.

For each Pokémon, if the current number of candies ( m_i ) is at least ( k_i ), then it can evolve. After an evolution, its current candies become ( m_i - k_i + 2 ). This process repeats until there are fewer than ( k_i ) candies remaining.

Formally, for a given Pokémon with initial candies ( m_i ) and evolution cost ( k_i ) (with ( k_i > 2 )), the number of evolutions possible is given by: [ \text{evolutions} = \begin{cases} \left\lfloor \frac{m_i - k_i}{k_i - 2} \right\rfloor + 1, & \text{if } m_i \ge k_i;\ 0, & \text{otherwise.} \end{cases} ]

Output two numbers: the total number of evolutions over all Pokémon and the 1-indexed position of the Pokémon that evolves the most times (if there is a tie, choose the Pokémon that appears first).

inputFormat

The first line contains an integer ( n ), representing the number of Pokémon. Each of the next ( n ) lines contains two integers ( m_i ) and ( k_i ) separated by a space, where ( m_i ) is the initial number of candies for the ( i)-th Pokémon and ( k_i ) is the number of candies required for one evolution.

outputFormat

Output two space-separated integers: the total number of evolutions that can be performed and the 1-indexed position of the Pokémon that achieves the maximum evolutions. In case of a tie, output the one that appeared earliest in the input.

sample

3
12 5
20 6
15 5
11 2