455. Maximum Units on a Truck
EasyGreedySorting
Box type i has count boxes, each holding units units. The truck takes at most size boxes. Print the maximum total units.
Input format
Line 1: n size Next n lines: count units
Output format
The maximum units.
Example 1
Input
3 4 1 3 2 2 3 1
Output
8
Example 2
Input
4 10 5 10 2 5 4 7 3 9
Output
91
Constraints
1 ≤ n ≤ 1000
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…