Putnam Rank Range
InterviewTime limit2sMemory limit512 MB
Given the average rank for each distinct score, find the rank range occupied by the block of contestants holding your score.
- Level
Medium5 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
After strong results in programming contests, you take part in the Putnam mathematical competition. In this contest a higher score means a better (smaller) rank. Contestants who attain the same score are all tied and together occupy a block of consecutive ranks.
The average rank of a score is the arithmetic mean of the ranks occupied by the contestants who attained it. For example, if three people are tied across ranks 1, 2 and 3, the average rank of that score is .
Given the average rank of every distinct score, determine the exact range of ranks (from the best rank to the worst rank) that your score occupies. For instance, if contestants scored higher than you and, counting yourself, contestants share your score, then your range is –.
Input
The first line contains an integer ().
Each of the next lines contains two numbers separated by a space. The first is a score attained by one or more contestants; it is an integer with . The second is the average rank for that score, with ; it is a decimal that is always a multiple of (for example 20.5).
The last line contains your score, which is guaranteed to equal the first number on one of the previous lines.
The score lines are not necessarily given in sorted order.
Output
Print two lines: the best (smallest) rank and the worst (largest) rank of the block of contestants who share your score, in that order.