COCI '16 Contest 2 #1 Go

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type

Mirko quickly got tired of Jetpack Joyride and started playing Pokémon GO! on his phone. One of the curiosities of this game is the so-called evolution of Pokémon.

In order to evolve Pokémon of species P_i, Mirko must provide K_i candy intended for a Pokémon of that species. After the evolution of that Pokémon, he gets 2 candies back. Pokémon can evolve only with the help of candy intended for their species.

Mirko has N species of Pokémon and M_i candy for Pokémon of species P_i and wants to know how many total Pokémon he can evolve.

He also wants to know which Pokémon can evolve the most number of times. If there are multiple such Pokémon, output the one with the smallest Pokédex number. In other words, the one that appears earliest in the input data.

Input Specification

The first line of input contains the integer N (1 \leq N \leq 70), the number of Pokémon species. The following 2N lines contains N sets of data, wherein it holds:

  • Line 2i contains string P_i, 20 characters long at most, the name of the i^\text{th} Pokémon species;
  • Line 2i+1 contains integers K_i (12 \leq K_i \leq 400) and M_i (1 \leq M_i \leq 10^4), the number of candy necessary for the evolution of one Pokémon of the i^\text{th} species and the total number of candy Mirko has for Pokémon of the i^\text{th} species.

Output Specification

The first line of output must contain the total number of Pokémon that Mirko can evolve. The second line of output must contain the name of the Pokémon that can evolve the most number of times.

Scoring

In test cases worth 16 points total, it will hold N = 3.

The first line of output will count towards 50\% of points for that test case.

The second line of output will count towards 50\% of points for that test case.

Sample Input 1

4
Caterpie
12 33
Weedle
12 42
Pidgey
12 47
Rattata
25 71

Sample Output 1

14
Weedle

Explanation for Sample Output 1

Let's describe how Mirko evolved Weedles. For Weedles' first evolution, Mirko spent 12 candy, but got back 2, so he has 32 candy left (42-12+2). After the second evolution, he is left with 22 candy. After the third evolution, he had 12 candy, which was enough for just one more evolution. This way, Mirko evolved 4 Weedles.

Similarly, we see that Mirko can evolve at most 3 Caterpies, 4 Pidgeys and 3 Rattatas.

Out of all Pokémon, Weedle and Pidgey evolved the most number of times, but Weedle's Pokédex number is smaller (it appears earlier in the input data), so it is the solution of the second part of the task.

Sample Input 2

7
Bulbasaur
25 74
Ivysaur
100 83
Charmander
25 116
Charmeleon
100 32
Squirtle
25 1
Wartortle
100 173
Pikachu
50 154

Sample Output 2

11
Charmander

Comments

There are no comments at the moment.