Problem 974
Minimum Sum of Four Digit Number After Splitting Digits
Easy · 10 pts · Math, Greedy, Sorting
Problem
Split the four digits of a positive four-digit number NUM into two new numbers, using every digit exactly once (leading zeros are allowed in the new numbers). Minimise the sum of the two new numbers. Sort the four digits: the two smallest should become the tens digits and the two largest the units digits, so the answer is 10 × (d1 + d2) + (d3 + d4).
Input
A single four-digit integer NUM.
Output
Print the minimum possible sum.
Constraints
1000 <= NUM <= 9999
Example input
2932
Example output
52
Explanation
The digits of 2932 sorted are 2 2 3 9. Forming 23 and 29 gives 52, the smallest possible sum.