#C9776. Minimum Number of Boxes to Open
Minimum Number of Boxes to Open
Minimum Number of Boxes to Open
You are given several test cases. In each test case, there are several boxes containing items. There are exactly 10 participants, and each participant must receive exactly one item. The items are stored in boxes with varying numbers of items. Your task is to determine the minimum number of boxes you need to open so that the total number of items from these boxes is at least 10. If the total number of items available in all boxes is less than 10, output "Not enough items in boxes to distribute".
Note: When selecting boxes, you should open the boxes with the most items first in order to minimize the number of boxes opened. All input is provided via standard input (stdin) and the output should be printed to standard output (stdout).
Formula:
Let \( S \) be the sorted list of items in descending order. Then, find the smallest \( k \) such that:
[ \sum_{i=1}^{k} S_i \ge 10 ]
If \( \sum_{i=1}^{n} S_i < 10 \), output "Not enough items in boxes to distribute".
inputFormat
The first line contains a single integer \( T \) which denotes the number of test cases. Each test case consists of two lines:
- The first line of each test case contains an integer \( n \) indicating the number of boxes.
- The second line contains \( n \) space-separated integers representing the number of items in each box.
Input is read from standard input (stdin).
outputFormat
For each test case, print the minimum number of boxes required to reach at least 10 items. If it is not possible, print "Not enough items in boxes to distribute" on a separate line. Output is printed to standard output (stdout).
## sample2
4
3 5 2 6
3
10 10 10
2
1
</p>