The score game

4

6 votes
Algorithms, Basics of Greedy Algorithms, C++, Greedy Algorithms
Problem

You are given an array A of N elements where each element is a pair represented by (X[i],Y[i])

Bob and Alice play a game where both of them have to pick some elements from the array A. Suppose, Bob picked the elements at index i1,i2,...,iK where KN.

  • Score(Bob) = j(X[j]+Y[j]), where j belongs to (i1,i2,....,iK) .
  • Score(Alice) = jX[j], where j belongs to (1,2,....,N) excluding (i1,i2,....,iK).

Find the minimum number of elements Bob must pick such that the score of Bob is greater than Alice.

Note: 1-based indexing is used.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • For each test case:
    • The first line contains an integer N.
    • The second line contains N space-separated integers denoting the first element of the pair.
    • The third line contains N space-separated integers denoting the second element of the pair.

Output format

For each test case, print the minimum number of elements Bob needs to pick to score greater than Alice.

Constraints

1T101N1051X[i],Y[i]106

 

Sample Input
1
4
3 1 2 4
4 1 3 3
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • If Bob element at index 4th.
    • Score of Bob = 4 + 3 = 7
    • Score of Alice = 3 + 1 +  2 = 6
  • Hence, required answer is 1.
Editor Image

?