2016-17 Woburn Challenge Finals Round - Senior Division
Angus and Bessie are the most well-known grenadiers in Bo Vine's army, and they're constantly trying to out-do one another. Even on the very eve of the war's first major battle, they've ended up in an argument! On this occasion, they're fighting over how to split up the army's supply of grenades – of course, each of them wants the most powerful grenades to themselves! In an attempt at fairness, they're going to play a game to divide up the grenades.
There are boxes of grenades. The -th box contains grenades, with the -th of those grenades having a "grenade power" of , indicating its explosive strength. There are at most grenades in total across all of the boxes.
Angus and Bessie will take turns performing actions, with Angus going first, until each of the grenades has been taken by one of them. All of the boxes are initially sealed. In one turn, a cow may either unseal a sealed box, or take one grenade from an unsealed box. Both cows will make optimal actions with the goal of maximizing the total grenade power of the grenades that they'll get their hands on throughout the game (and thus minimizing the total grenade power obtained by their opponent).
To make things more exciting, the entire game will actually be independently re-played separate times. Before the -th time the game gets played, a single grenade will get swapped out for a slightly different one. In particular, the -th grenade in the -th box will be replaced with a new grenade whose grenade power is larger than that of the removed grenade. It's guaranteed that the new grenade's power will still be positive. Each such replacement will carry over to all subsequent times the game gets played, and the new grenade itself may get replaced later on.
Help Angus and Bessie determine the outcome of their set of games by predicting how much grenade power each of them will end up with each time they play. Rather than outputting all such values (the grenade power obtained by Angus and Bessie each time they play), you only need to compute the sum of Angus's values, as well as the sum of Bessie's values.
In test cases worth of the points, , , and
.
In test cases worth another of the points, .
In test cases worth another of the points, ,
and there are at most grenades in total.
Input Specification
The first line of input consists of two space-separated integers and .
lines follow, the -th of which consists of an integer ,
followed by a space, followed by space-separated integers
(for ).
lines follow, the -th of which consists of three space-separated
integers , , and (for ).
Output Specification
Output a single line consisting of two space-separated integers – the total grenade power obtained by Angus and Bessie, respectively.
Sample Input
3 3
2 4 3
1 5
2 1 1
3 2 1
3 2 1
2 1 -1
Sample Output
17 29
Sample Explanation
After the first grenade replacement, assuming both cows play optimally,
Angus will end up obtaining grenade power (for example, he may get
from the st grenade in the st box, and from the st grenade in the
rd box), while Bessie will obtain from the remaining grenades.
After the second replacement, Angus will obtain while Bessie will
obtain . After the third replacement, Angus will obtain while Bessie
will obtain . In total, then, Angus will have obtained
grenade power, while Bessie will have obtained .
Comments