CF1443C.The Delivery Dilemma

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya is preparing for his birthday. He decided that there would be nn different dishes on the dinner table, numbered from 11 to nn. Since Petya doesn't like to cook, he wants to order these dishes in restaurants.

Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his orders from nn 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:

  • the dish will be delivered by a courier from the restaurant ii, in this case the courier will arrive in aia_i minutes,
  • Petya goes to the restaurant ii on his own and picks up the dish, he will spend bib_i minutes on this.

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.

For example, if Petya wants to order n=4n = 4 dishes and a=[3,7,4,5]a = [3, 7, 4, 5], and b=[2,1,2,4]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 33 minutes, the courier of the fourth restaurant will bring the order in 55 minutes, and Petya will pick up the remaining dishes in 1+2=31 + 2 = 3 minutes. Thus, in 55 minutes all the dishes will be at Petya's house.

Find the minimum time after which all the dishes can be at Petya's home.

佩佳正在为自己的生日做准备。他决定晚餐桌上将有 nn 道各不相同的菜肴,编号从 11 到 nn。由于佩佳不喜欢做饭,他打算从餐馆订购这些菜肴。

不幸的是,所有菜肴都在不同的餐馆制作,因此佩佳需要从 nn 个不同的地点取餐。为了加快这一过程,他希望在部分餐馆选择外卖配送服务。因此,对于每道菜肴,佩佳有两种获取方式:

  • 由第 ii 家餐馆的外卖员配送该菜肴,此时外卖员将在 aia_i 分钟后送达;
  • 佩佳亲自前往第 ii 家餐馆取餐,这将花费他 bib_i 分钟。

每家餐馆都有各自的外卖员,且所有外卖员均在佩佳离家的同一时刻开始配送(即所有外卖并行进行)。佩佳必须亲自前往所有他未选择外卖配送的餐馆取餐,且这些行程是依次连续进行的(即串行)。

例如,若佩佳要订购 n=4n = 4 道菜肴,且 a=[3,7,4,5]a = [3, 7, 4, 5],b=[2,1,2,4]b = [2, 1, 2, 4],那么他可以选择由第 1 和第 4 家餐馆提供外卖配送,而亲自前往第 2 和第 3 家餐馆取餐。此时:第 1 家餐馆的外卖员将在 33 分钟后送达,第 4 家餐馆的外卖员将在 55 分钟后送达;佩佳亲自取餐需耗时 1+2=31 + 2 = 3 分钟。因此,所有菜肴将在 55 分钟后全部抵达佩佳家中。

请计算所有菜肴全部抵达佩佳家所需的最短时间。

输入格式

The first line contains one positive integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5) — the number of test cases. Then tt test cases follow.

Each test case begins with a line containing one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of dishes that Petya wants to order.

The second line of each test case contains nn integers a1…ana_1 \ldots a_n (1≤ai≤1091 \le a_i \le 10^9) — the time of courier delivery of the dish with the number ii.

The third line of each test case contains nn integers b1…bnb_1 \ldots b_n (1≤bi≤1091 \le b_i \le 10^9) — the time during which Petya will pick up the dish with the number ii.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个正整数 tt(1≤t≤2⋅1051 \le t \le 2 \cdot 10^5)—— 测试用例的数量。随后是 tt 个测试用例。

每个测试用例以一行开始,该行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— Petya 想要订购的菜肴数量。

每个测试用例的第二行包含 nn 个整数 a1…ana_1 \ldots a_n(1≤ai≤1091 \le a_i \le 10^9)—— 编号为 ii 的菜肴的快递配送时间。

每个测试用例的第三行包含 nn 个整数 b1…bnb_1 \ldots b_n(1≤bi≤1091 \le b_i \le 10^9)—— Petya 取走编号为 ii 的菜肴所需的时间。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output one integer — the minimum time after which all dishes can be at Petya's home.

对于每个测试用例,输出一个整数——所有菜肴都能到达佩蒂亚家的最短时间。

输入输出样例

  • 输入#1

    4
    4
    3 7 4 5
    2 1 2 4
    4
    1 2 3 4
    3 3 3 3
    2
    1 2
    10 10
    2
    10 10
    1 2

    输出#1

    5
    3
    2
    3

输入解题思路,AI测评打分。不知道怎么写?

首页