The score game
Practice
4 (6 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
16% Success 1325 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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 \(i_1, i_2, ..., i_K\) where \(K \le N\).
- Score(Bob) = \(\sum_\limits{j} (X[j] + Y[j])\), where \(j\) belongs to \((i_1,i_2,....,i_K)\) .
- Score(Alice) = \(\sum_\limits{j} X[j]\), where \(j\) belongs to \((1,2,....,N)\) excluding \((i_1,i_2,....,i_K)\).
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
\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 1 \le X[i] , Y[i] \le 10^6\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
57 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationMathSorting
Points:30
7 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
17 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Editorial