Time is of the Essence
Time limit2sMemory limit512 MB
Given a chain of unit conversions and an amount in the smallest unit, print a rounded answer in the largest unit and a rough answer in the top two units.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Do you know how long one million seconds is? How about one billion seconds? The exact answer to the first question is 11 days, 13 hours, 46 minutes and 40 seconds. That is accurate, but it is chopped much finer than anyone needs. A useful answer is "11 days, 14 hours", or just "12 days" after rounding. Three million inches works the same way: "47 miles", or "47 miles, 613 yards". This problem asks for those two rough answers for a given chain of units.
Input
The first line has this form.
n name_1 c_1 name_2 c_2 ... name_{n-1} c_{n-1} name_n
Each is the name of a unit, and each says how many units of type fit in one unit of type . For example, a first line of 4 days 24 hours 60 minutes 60 seconds says that one day has 24 hours, one hour has 60 minutes and one minute has 60 seconds. is the number of unit names, and . Every name is an alphabetic string with no blanks and is already written in plural form. Print the given name as it is, whatever number stands next to it. Every is a positive integer, and the product is at most .
The second line has the amount measured in the last unit ().
Output
Print two lines. Let be the number of units in one unit, and let be the number of units in one unit.
The first line holds rounded to the nearest integer, a space, then .
The second line holds and , then the leftover divided by and rounded to the nearest integer, then .
Rounding goes up whenever the fractional part is or more. The second line does no carrying, so its second number is sometimes equal to . Do not print thousands separators.