The Eldest
Time limit3sMemory limit1024 MB
Each person has a distinct birth year and a death year; count how many years each person was the oldest living resident at the New Year's speech.
- Level
Medium7 of 10
- Topics
- Sorting, Intervals, Simulation, Implementation
- Solved
- No attempts yet
Problem
A long time ago there was a small village named Stackköping. The residents of Stackköping had several special traditions. One tradition was that at the end of every year, the oldest living resident had to give a New Year's speech. Another tradition was that at most one new person was allowed to be born each year, and according to some experts this was what eventually led to the downfall of Stackköping.
At an archaeological excavation, a document was found showing the years in which all people who ever lived in Stackköping were born and died. You have come into possession of this document and want to calculate how many New Year's speeches each person gave.
The New Year's speech is always the very last thing that happens each year, so no one is born or dies after the speech that occurs in the same year. If no one is alive at the New Year, then of course no speech is held. Otherwise a speech is always held, even if only one person is alive.
Input
The first line contains an integer (): the number of people. The following lines contain two integers and (): the years in which person number was born and died. All the numbers are distinct.
Output
Print lines with one integer on each, where the th number is how many New Year's speeches the th person gave.