CF1729D.Friends and the Restaurant

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A group of nn friends decide to go to a restaurant. Each of the friends plans to order meals for xix_i burles and has a total of yiy_i burles (1≤i≤n1 \le i \le n).

The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all xix_i values in the group must not exceed the sum of yiy_i values in the group.

What is the maximum number of days friends can visit the restaurant?

For example, let there be n=6n = 6 friends for whom xx = [8,3,9,2,4,58, 3, 9, 2, 4, 5] and yy = [5,3,1,4,5,105, 3, 1, 4, 5, 10]. Then:

  • first and sixth friends can go to the restaurant on the first day. They will spend 8+5=138+5=13 burles at the restaurant, and their total budget is 5+10=155+10=15 burles. Since 15≥1315 \ge 13, they can actually form a group.
  • friends with indices 2,4,52, 4, 5 can form a second group. They will spend 3+2+4=93+2+4=9 burles at the restaurant, and their total budget will be 3+4+5=123+4+5=12 burles (12≥912 \ge 9).

It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.

So, the maximum number of groups the friends can split into is 22. Friends will visit the restaurant for a maximum of two days. Note that the 33-rd friend will not visit the restaurant at all.

Output the maximum number of days the friends can visit the restaurant for given nn, xx and yy.

nn 位朋友决定去一家餐厅。每位朋友计划点价值 xix_i 卢布的餐食,且各自共有 yiy_i 卢布(1≤i≤n1 \le i \le n)。

朋友们决定将此次餐厅之行分若干天完成。每天,至少两位朋友组成一组前往餐厅;每位朋友至多去一次(即这些组两两不相交)。这些组需满足如下条件:每组的总预算(即组内所有成员的 yiy_i 之和)不少于该组在餐厅的总消费(即组内所有成员的 xix_i 之和)。换言之,组内所有 xix_i 的和不得超过组内所有 yiy_i 的和。

朋友们最多能去餐厅多少天?

例如,设有 n=6n = 6 位朋友,其 x=[8,3,9,2,4,5]x = [8, 3, 9, 2, 4, 5],y=[5,3,1,4,5,10]y = [5, 3, 1, 4, 5, 10]。则:

  • 第 11 位与第 66 位朋友可在第一天一同前往餐厅。他们在餐厅将消费 8+5=138+5=13 卢布,而他们的总预算是 5+10=155+10=15 卢布。由于 15≥1315 \ge 13,他们确实可组成一组。
  • 第 22、44、55 位朋友可组成第二组。他们在餐厅将消费 3+2+4=93+2+4=9 卢布,而他们的总预算为 3+4+5=123+4+5=12 卢布(12≥912 \ge 9)。

可以证明,无法再划分出更多满足“每组至少两人”且“每组均能支付账单”的组。

因此,朋友们最多能划分为 22 组,即最多去餐厅 22 天。注意:第 33 位朋友将全程不前往餐厅。

给定 nn、数组 xx 和 yy,请输出朋友们最多能去餐厅的天数。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case contains a single integer nn (2≤n≤1052 \le n \le 10^5) — the number of friends.

The second line of each test case contains exactly nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (1≤xi≤1091 \le x_i \le 10^9). The value of xix_i corresponds to the number of burles that the friend numbered ii plans to spend at the restaurant.

The third line of each test case contains exactly nn integers y1,y2,…,yny_1, y_2, \dots, y_n (1≤yi≤1091 \le y_i \le 10^9). The value yiy_i corresponds to the number of burles that the friend numbered ii has.

It is guaranteed that the sum of nn values over all test cases does not exceed 10510^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)—— 表示朋友的数量。

每个测试用例的第二行包含恰好 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(1≤xi≤1091 \le x_i \le 10^9)。其中 xix_i 表示编号为 ii 的朋友计划在餐厅花费的 burles 数量。

每个测试用例的第三行包含恰好 nn 个整数 y1,y2,…,yny_1, y_2, \dots, y_n(1≤yi≤1091 \le y_i \le 10^9)。其中 yiy_i 表示编号为 ii 的朋友所拥有的 burles 数量。

保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.

对于每个测试用例,输出访问餐厅的最大天数。如果朋友们甚至无法组成一个小组去餐厅,则输出 0。

输入输出样例

  • 输入#1

    6
    6
    8 3 9 2 4 5
    5 3 1 4 5 10
    4
    1 2 3 4
    1 1 2 2
    3
    2 3 7
    1 3 10
    6
    2 3 6 9 5 7
    3 2 7 10 6 10
    6
    5 4 2 1 8 100
    1 1 1 1 1 200
    6
    1 4 1 2 4 2
    1 3 3 2 3 4

    输出#1

    2
    0
    1
    3
    1
    3

说明/提示

The first test case in explained in the problem statement.

In the second test case, friends cannot form at least one group of two or more people.

In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends (1+3+10≥2+3+71+3+10 \ge 2+3+7). Note that they do not have the option of splitting into two groups.

题目陈述中已解释第一个测试用例。

在第二个测试用例中,朋友们无法组成至少一个包含两人或以上成员的小组。

在第三个测试用例中,一种在一天内访问餐厅的方式是三人全部组成一个小组前往(1+3+10≥2+3+71+3+10 \ge 2+3+7)。注意,他们没有选择分成两个小组的选项。

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

首页