PickingUp
SRM 430 · 2008-12-20 · by Janq
Problem Statement
Notes
- A sequence A comes before sequence B lexicographically if A has a smaller value at the first position where the sequences differ.
Constraints
- score1 and score2 will contain between 2 and 36 elements, inclusive.
- score1 and score2 will contain the same number of elements.
- score1 and score2 will each contain an even number of elements.
- Each element of score1 and score2 will be between 1 and 10^15, inclusive.
{1,2,1,2}
{2,1,2,1}
Returns: {1, 1, 2, 2 }
{5,9}
{8,6}
Returns: {1, 2 }
If we assign the first player to the first team and the second player to the second team, the team scores will be 5 and 6. In the opposite case, the team scores would be 8 and 9. In both cases, the difference is equal to 1. The answer is {1,2} because it comes before {2,1} lexicographically.
{2,3,4,7}
{2,4,5,8}
Returns: {1, 2, 2, 1 }
The only way to balance the teams is to assign the first and last players to the first team. The first team's score will be 2+7 and the second team's score will be 4+5.
{1,5,6,8}
{7,5,3,1}
Returns: {1, 2, 1, 2 }
We cannot balance these teams evenly. We can come close by assigning the first and third players to the first team. The first team's score will then be 7 and the second team's score will be 6.
{300,300,300,300}
{600,10,10,10}
Returns: {2, 1, 1, 2 }
{50,50,50,1}
{30,30,30,150}
Returns: {1, 2, 2, 1 }
Teams must be of equal size.
Submissions are judged against all 119 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PickingUp with a public method vector<int> fairPickingUp(vector<long long> score1, vector<long long> score2) · 119 test cases · 2 s / 256 MB per case