AmazonOA #290
Optimizing Box Weights
Estimated EasyJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Split all items, by identity, into A and B, with each item in exactly one group; different items with the same weight are still separate. You need sum(A)>sum(B). First minimize the number of items in A, then, among the minimum counts, maximize the total weight of A, and output the weights of A in ascending order. B may be empty.
Input
The first line contains n and the second line contains the weights. 1≤n≤100000, 1≤arr[i]≤10000.
Output
Output the weights of the items in A in ascending order, separated by spaces; a repeated weight is printed once per item.
Example 1
Input:
6
5 3 2 4 1 2
Output:
4 5
Example 2
Input:
5
4 2 5 1 6
Output:
5 6
Example 3
Input:
2
2 2
Output:
2 2
Example notes
The answers are 4 5, 5 6 and 2 2 respectively. In the third example, choosing one item only ties, so both items must go into A.
Editorial
Loading solution…