Lost Island
Time limit2sMemory limit512 MB
Given each eye color's true count a_i and the traveler's lower bound b_i, find the last day of suicides and the total number of people who die.
Problem
An island far away is home to a tribe. The tribe has eye colors. There are people with eye color (), and the tribe knows of no other colors. Strictly speaking, the tribe knows the value of but does not know that every .
The tribe follows a religion in which anyone who can deduce their own eye color commits suicide the next day. The people of the tribe are extremely clever.
On day 0, a traveler arrives on the island, meets the tribe, and makes true statements, where and at least one .
- Wow, there are at least people with eye color 1!
- Wow, there are at least people with eye color 2!
- ...
- Wow, there are at least people with eye color !
Find the last day on which suicides take place, and the total number of people who commit suicide.
Input
The first line contains an integer (), the number of eye colors.
Each of the next lines contains two integers and (, , at least one is greater than 0). Here is the number of people with eye color , and is the lower bound on that number stated by the traveler.
Output
Print two integers: the number of the last day on which suicides take place, and the total number of people who commit suicide.
Hint
Here is what happens in the first sample. The person with eye color 1 sees no one else with that color but hears that at least one person has it. They work out who that person could be and commit suicide on day 1.
Everyone else knows that only two colors exist and that one person with eye color 1 has died. They conclude that all of them have eye color 2 and commit suicide on day 2.