Universal Cup Judging System

Universal Cup

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓
统计

Description

You are the leader of a school programming competition team in Chongqing for the CCPC. To enhance team bonding after the contest, you wish to organize a group dinner. However, since the budget was exhausted on hotpot before the competition, the cost of the meal must be split equally (that is, if $k$ people attend a meal with a total cost of $W$, each person pays $\frac{W}{k}$) among all participants.

There are $n$ classmates in the team. Each classmate who attends the dinner will order exactly one dish. The $i$-th classmate orders a dish costing $w_i$. Each classmate also has a budget constraint $r_i$: if the final shared cost of the meal exceeds $r_i$, the $i$-th classmate will stay at the hotel and order takeout instead.

As the leader, you want to maximize the number of classmates attending the dinner. Your goal is to select a subset of $m$ classmates such that if they each order their respective dishes, the shared cost (the sum of their $m$ dish prices divided by $m$) does not exceed the budget $r_i$ of any of the $m$ selected classmates. Find the maximum possible value of $m$.

If no such subset exists for $m \ge 1$, output $0$.

Input

There are multiple test cases in a single test file. The first line of the input contains a single integer $T$ ($1 \le T \le 10^5$), indicating the number of test cases.

For each test case:

  • The first line of the input contains a single integer $n$ ($1 \le n \le 10^5$), representing the number of classmates.
  • Next, input a line with $n$ integers, where the $i$-th integer $w_i$ ($1 \le w_i \le 10^9$) represents the price of the dish ordered by the $i$-th classmate.
  • Then, input a line with $n$ integers, where the $i$-th integer $r_i$ ($1 \le r_i \le 10^9$) represents the maximum price the $i$-th classmate is willing to pay.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

Output

For each test case, output a line with a single integer, representing the answer.

Example

Sample Input 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

Sample Output 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.