codeforces-scrape

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

1610C.md (1505B)


      1 Source: https://codeforces.com/problemset/problem/1610/C
      2 
      3 C. Keshi Is Throwing a Party
      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 Keshi is throwing a party and he wants everybody in the party to be happy.
     22 
     23 He has $n$ friends. His $i$-th friend has $i$ dollars.
     24 
     25 If you invite the $i$-th friend to the party, he will be happy only if at most $a_i$ people in the party are strictly richer than him and at most $b_i$ people are strictly poorer than him.
     26 
     27 Keshi wants to invite as many people as possible. Find the maximum number of people he can invite to the party so that every invited person would be happy.
     28 
     29 Input
     30 
     31 The first line contains a single integer $t$ $(1\le t\le 10^4)$ — the number of test cases. The description of the test cases follows.
     32 
     33 The first line of each test case contains a single integer $n$ $(1\le n\le 2 \cdot 10^5)$ — the number of Keshi's friends.
     34 
     35 The $i$-th of the following $n$ lines contains two integers $a_i$ and $b_i$ $(0 \le a_i, b_i \lt n)$.
     36 
     37 It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case print the maximum number of people Keshi can invite.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 3
     49 3
     50 1 2
     51 2 1
     52 1 1
     53 2
     54 0 0
     55 0 1
     56 2
     57 1 0
     58 0 1
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 2
     65 1
     66 2
     67 ```
     68 
     69 Note
     70 
     71 In the first test case, he invites the first and the second person. If he invites all of them, the third person won't be happy because there will be more than $1$ person poorer than him.