Problem 1: Falling Apart

https://open.kattis.com/problems/fallingapart

Since both Bob and Alice optimally seek to acquire the largest possible sum of integers possible and Alice always moves first, we expect Alice to choose the biggest piece, and then Bob to choose the second biggest piece, and then Alice to choose the third biggest piece, etc.

3  1  2        Example given
               Alice: 0, Bob: 0

3  1  2        Alice chooses 3
A              Alice: 3, Bob: 0

3  1  2        Bob chooses 2
A     B        Alice: 3, Bob: 2

3  1  2        Alice chooses 1
A  A  B        Alice: 4, Bob: 2

We can make our lives easier by sorting the pieces in descending order (biggest to smallest). That way, Alice chooses the first piece, and then Bob chooses the second piece, and then Alice chooses the third piece, etc.

Implementation Tips:

# Sort a vector in ascending order
sort(vect.begin(), vect.end());

# Sort a vector in descending order
sort(vect.begin(), vect.end(), greater<int>());

Last updated