#C1866. Optimal Marathon Day
Optimal Marathon Day
Optimal Marathon Day
You are given T participants, each of whom can attend a marathon on a range of days specified by two integers L and R. Your task is to determine the day that maximizes the number of available participants. If there is more than one day with the maximum number of available participants, choose the earliest day.
Let the total number of days be limited by \(10^5\) (i.e. 100000). For each participant with an available range \([L, R]\), they are available on every day \(d\) such that \(L \leq d \leq R\).
Example: For participants with ranges (1, 3), (2, 5), and (4, 6), the day counts are as follows:
- Day 1: 1 participant
- Day 2: 2 participants
- Day 3: 2 participants
- Day 4: 2 participants
- Day 5: 1 participant
- Day 6: 1 participant
inputFormat
The input is read from stdin and has the following format:
T L1 R1 L2 R2 ... LT RT
Where the first line is an integer T, the number of participants, and the next T lines each contain two integers L and R, representing the range of days during which each participant is available.
outputFormat
Output a single integer to stdout representing the optimal day to hold the marathon such that the number of available participants is maximized. If multiple days yield the same maximum number of participants, output the earliest day.
## sample3
1 3
2 5
4 6
2
</p>