ДИНИ
InterviewTime limit1sMemory limit1024 MB
Given four watermelon weights, split them between two hands so the absolute difference of the two sums is as small as possible.
- Level
Easy3 of 10
- Topics
- Brute force, Array, Math
- Solved
- No attempts yet
Problem
A superhero has to carry 4 large watermelons. He wants to distribute them between his two hands so that the difference in kilograms between the hands is as small as possible.
Write a program dini that computes this minimum value.
Input
The first line of the standard input contains 4 positive integers separated by a single space, the weights in kilograms of each watermelon.
Output
The first line of the standard output must contain one non-negative integer, the minimum value of the difference between the sums of the weights of the watermelons placed in the superhero's left and right hands.
Constraints
- 0 ≤ weight of a watermelon < 100
Hint
Explanation of example 1: The watermelons are distributed so that the left hand holds 4+7 kilograms and the right hand holds 2+8. The corresponding sums are 11 and 10. The difference between the larger and the smaller is 1.
Explanation of example 2: The left hand takes the three watermelons weighing 2 kilograms each, and the right hand takes the watermelon weighing 8 kilograms.