A13937 | The Delivery Dilemma
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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:
- the dish will be delivered by a courier from the restaurant $i$ , in this case the courier will arrive in $a_i$ minutes,
- Petya goes to the restaurant $i$ on his own and picks up the dish, he will spend $b_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 = 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.
Find the minimum time after which all the dishes can be at Petya's home.
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:
- the dish will be delivered by a courier from the restaurant $i$ , in this case the courier will arrive in $a_i$ minutes,
- Petya goes to the restaurant $i$ on his own and picks up the dish, he will spend $b_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 = 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.
Find the minimum time after which all the dishes can be at Petya's home.
输入格式
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.
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.
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$ .
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$ .
The sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
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.
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$ .
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$ .
The sum of $n$ over all test cases does not exceed $2 \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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted