LCC/Moose '19 Contest 4 J1 - Growing Plants

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem type

You recently came into possession of N plants. Each of these plants starts out with a height of 5, and will grow or decrease in height every day. You want to know, after D days, which the tallest and shortest plants are.

Input Specification

The first line contains two integers, N (1 \leq N \leq 100) and D (1 \leq D \leq 100), the number of plants you were given and the number of days you check them after.

The next N lines will contain S (1 \leq |S| \leq 100) the name of the plant, and G (-500 \leq G \leq 500) the amount the plant grows or decreases in height per day, separated by spaces. It is guaranteed that the name of the plant will be unique and will only contain lowercase alphabetical characters.

Output Specification

On the first line, output the name and height of the plant that is the tallest after D days. On the second line, output the name and height of the plant that is the shortest after D days. If multiple plants have the shortest or tallest height, output the one earliest in the input.

Note that for this question, the plant heights can go into the negatives.

Sample Input 1

3 5
bob -2
plant 5
steve 2

Sample Output 1

plant 30
bob -5

Sample Input 2

1 1
bob 50

Sample Output 2

bob 55
bob 55


There are no comments at the moment.