Algorithm


Problem Name: 2 AD-HOC - beecrowd | 2345

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2345

Assigning Teams

 

By Pablo Ariel Heiber AR Argentina

Timelimit: 1

Four friends are playing table tennis. Each of them has a skill level which is represented by an integer number: the higher the number, the better the player is.

The four friends want to form two teams of two players each. For the game to be more exciting, they want the skill level of the teams to be as close as possible. The skill level of a team is the sum of the skill levels of the players in that team.

Although they are very good table tennis players, these friends are not so good at other things, like Math or Computing. Can you help them find the smallest possible difference between the teams’ skill levels?

 

Input

 

The input consists of a single line that contains four integers A, B, C and D, representing the skill levels of the four players (0 ≤ A ≤ B ≤ C  D ≤ 104).

 

Output

 

Output a line with an integer representing the smallest difference between the skill levels for both teams.

 

 

 

Input Samples Output Samples

4 7 10 20

7

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int pos1 = abs(a + b - c - d);
    pos1 = min(pos1, abs(a + c - b - d));
    pos1 = min(pos1, abs(a + d - b - c));
    pos1 = min(pos1, abs(b + d - a - c));
    pos1 = min(pos1, abs(b + c - a - d));
    pos1 = min(pos1, abs(c + d - a - b));
    printf("%d\n", pos1);
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
4 7 10 20

Output

x
+
cmd
7
Advertisements

Demonstration


Previous
#2344 Beecrowd Online Judge Solution 2344 Notas da Prova Solution in C, C++, Java, Js and Python
Next
#2346 Beecrowd Online Judge Solution 2346 Back to the Future Solution in C, C++, Java, Js and Python