IBMOA #69
Array Subsets (Frontend)
Estimated EasyJudge-ready
Topics (AI-labelled)Greedy
Split the array by element positions into A and B, keeping duplicate values. It is required that sum(A)>sum(B); first minimize the number of elements in A, then maximize the sum of A for that count, and return A in ascending order. B may be empty.
Input
The first line contains n, and the second line contains the array. Full original bounds: 1≤n≤100000, 1≤arr[i]≤100000.
Output
Output the number of elements in A on the first line, followed by one integer per line in non-decreasing order, keeping duplicates.
Example 1
Input:
6
5 3 2 4 1 2
Output:
2
4
5
Example 2
Input:
5
4 2 5 1 6
Output:
2
5
6
Example 3
Input:
2
1 1
Output:
2
1
1
Example notes
The outputs of the three public examples are, in order: 2 / 4 / 5; 2 / 5 / 6; 2 / 1 / 1. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…