codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1424G.md (1595B)


      1 Source: https://codeforces.com/problemset/problem/1424/G
      2 
      3 G. Years
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range $(1, 10^9)$! Therefore, the planet was named Longlifer.
     22 
     23 In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!
     24 
     25 Input
     26 
     27 The first line contains an integer $n$ ($1 \le n \le 10^5$) — the number of people.
     28 
     29 Each of the following $n$ lines contain two integers $b$ and $d$ ($1 \le b \lt d \le 10^9$) representing birth and death year (respectively) of each individual.
     30 
     31 Output
     32 
     33 Print two integer numbers separated by blank character, $y$  — the year with a maximum number of people alive and $k$  — the number of people alive in year $y$.
     34 
     35 In the case of multiple possible solutions, print the solution with minimum year.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3
     43 1 5
     44 2 4
     45 5 6
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 2 2
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 4
     58 3 4
     59 4 5
     60 4 6
     61 8 10
     62 ```
     63 
     64 Output
     65 
     66 ```
     67 4 2
     68 ```
     69 
     70 Note
     71 
     72 You can assume that an individual living from $b$ to $d$ has been born at the beginning of $b$ and died at the beginning of $d$, and therefore living for $d$ - $b$ years.