QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#15423. 晚餐邀请

Statistiques

你是参加 CCPC 重庆站的一支学校程序设计竞赛队伍的队长。为了在比赛后增强团队凝聚力,你希望组织一次聚餐。然而,由于赛前吃火锅已经耗尽了预算,这顿饭的费用必须由所有参与者平摊(即:如果有 $k$ 个人参加聚餐,总花费为 $W$,则每人支付 $\frac{W}{k}$)。

队伍里有 $n$ 名同学。每个参加聚餐的同学都会点恰好一道菜。第 $i$ 位同学点的菜价格为 $w_i$。每位同学也有一个预算限制 $r_i$:如果最终平摊的餐费超过了 $r_i$,第 $i$ 位同学就会留在酒店点外卖。

作为队长,你希望最大化参加聚餐的同学人数。你的目标是选择一个由 $m$ 名同学组成的子集,使得如果他们每个人都点各自的菜,平摊后的费用(这 $m$ 道菜的价格之和除以 $m$)不超过这 $m$ 名被选中的同学中任何人的预算 $r_i$。

求 $m$ 的最大可能值。

如果不存在任何满足 $m \ge 1$ 的子集,输出 0。

输入格式

输入中包含多个测试用例。输入的第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。

对于每个测试用例:

  • 第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示同学的数量。
  • 接下来一行包含 $n$ 个整数,其中第 $i$ 个整数 $w_i$ ($1 \le w_i \le 10^9$) 表示第 $i$ 位同学所点菜品的价格。
  • 再接下来一行包含 $n$ 个整数,其中第 $i$ 个整数 $r_i$ ($1 \le r_i \le 10^9$) 表示第 $i$ 位同学愿意支付的最大价格(预算)。

保证所有测试用例中 $n$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示答案。

样例

输入样例 1

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

输出样例 1

3
7

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.