codeforces-scrape

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

1443C.md (2688B)


      1 Source: https://codeforces.com/problemset/problem/1443/C
      2 
      3 C. The Delivery Dilemma
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 Petya is preparing for his birthday. He decided that there would be $n$ different dishes on the dinner table, numbered from $1$ to $n$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants.
     22 
     23 Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his orders from $n$ different places. To speed up this process, he wants to order courier delivery at some restaurants. Thus, for each dish, there are two options for Petya how he can get it:
     24 
     25 * the dish will be delivered by a courier from the restaurant $i$, in this case the courier will arrive in $a_i$ minutes,
     26 * Petya goes to the restaurant $i$ on his own and picks up the dish, he will spend $b_i$ minutes on this.
     27 
     28 Each restaurant has its own couriers and they start delivering the order at the moment Petya leaves the house. In other words, all couriers work in parallel. Petya must visit all restaurants in which he has not chosen delivery, he does this consistently.
     29 
     30 For example, if Petya wants to order $n = 4$ dishes and $a = [3, 7, 4, 5]$, and $b = [2, 1, 2, 4]$, then he can order delivery from the first and the fourth restaurant, and go to the second and third on your own. Then the courier of the first restaurant will bring the order in $3$ minutes, the courier of the fourth restaurant will bring the order in $5$ minutes, and Petya will pick up the remaining dishes in $1 + 2 = 3$ minutes. Thus, in $5$ minutes all the dishes will be at Petya's house.
     31 
     32 Find the minimum time after which all the dishes can be at Petya's home.
     33 
     34 Input
     35 
     36 The first line contains one positive integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of test cases. Then $t$ test cases follow.
     37 
     38 Each test case begins with a line containing one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of dishes that Petya wants to order.
     39 
     40 The second line of each test case contains $n$ integers $a_1 \ldots a_n$ ($1 \le a_i \le 10^9$) — the time of courier delivery of the dish with the number $i$.
     41 
     42 The third line of each test case contains $n$ integers $b_1 \ldots b_n$ ($1 \le b_i \le 10^9$) — the time during which Petya will pick up the dish with the number $i$.
     43 
     44 The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     45 
     46 Output
     47 
     48 For each test case output one integer — the minimum time after which all dishes can be at Petya's home.
     49 
     50 Example
     51 
     52 Input
     53 
     54 ```
     55 4
     56 4
     57 3 7 4 5
     58 2 1 2 4
     59 4
     60 1 2 3 4
     61 3 3 3 3
     62 2
     63 1 2
     64 10 10
     65 2
     66 10 10
     67 1 2
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 5
     74 3
     75 2
     76 3
     77 ```