Amplitude Hackathon Winter '24 Problem 3 - Killer Queen

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 0.5s
Memory limit: 1G

Problem type

Amplitude has installed the new hit arcade game, Killer Queen! Killer Queen is a 5v5 team game where teams of five players compete against each other. In the game, each team has one player serve as the queen and the other four players serve as drones. Before the game starts, each team can pick which player serves as the queen.

Conveniently, there are 10 people who wish to play Killer Queen, so they will split into two teams to play against each other. Each person has a skill level when playing as the queen and a (possibly different) skill level when playing as a drone. The strength of a team is the sum of the skill levels of the players depending on their assigned roles. The imbalance of the match between the two teams is equal to the absolute value of the difference of the strengths of the two teams.

To make the game as fun as possible, the 10 people coordinate to minimize the imbalance of the match. Compute the minimum possible imbalance.

Constraints

All skill levels are positive integers between 1 and 10^6, inclusive.

Input Specification

The first line of input contains ten integers, the skill levels of players 1, 2, \dots, 10 in order when playing as drones.

The second line of input contains ten integers, the skill levels of players 1, 2, \dots, 10 in order when playing as queens.

Output Specification

Output the minimum possible imbalance possible.

Sample Input 1

1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20

Sample Output 1

0

Sample Explanation 1

If players 3, 4, 5, 6, and 7 form a team with player 6 as the queen, their skill level is 3 + 4 + 5 + 12 + 7 = 31. If players 1, 2, 8, 9, and 10 form a team with player 1 as the queen, their skill level is 2 + 2 + 8 + 9 + 10 = 31. This results in a match with imbalance of 0.

Note that there are other arrangements which also result in an imbalance of 0.

Sample Input 2

31 41 59 26 53 58 98 93 23 84
27 18 28 18 28 45 90 45 23 53

Sample Output 2

0

Sample Explanation 2

An imbalance of 0 is attainable with one team having players 1, 2, 3, 6, and 7 with player 7 as the queen, and the other team having players 4, 5, 8, 9, and 10 with player 9 as the queen.

Sample Input 3

1 2 4 8 16 32 64 128 256 512
1 2 4 8 16 32 64 128 256 512

Sample Output 3

31

Sample Explanation 3

An imbalance of 31 is attainable with one team having players 5, 6, 7, 8 and 9 with player 5 as the queen, and the other team having players 1, 2, 3, 4, and 10 with player 10 as the queen.


Comments

There are no comments at the moment.