Hello!

I'm trying to solve problem D.Greedy Game from the SPb SU and SPb AU Contest of Pertozavodsk Winter Training Camp 2016.

Here are the problem statements.

I already searched for any solutions on the internet, I only found this.

The problem with it is that it's in chinese, the translation isn't understandable and I couldn't understand the code.

So can you give me some hints?

What I found so far is that to find the **maximal possible sum of values taken by the second player that he can guarantee regardless of the first player’s moves** we just have to find the maximal possible sum of values that the second player can take if the first player, when confronted by many items of the same biggest value *A*_{i}, picks the one with the biggest *B*_{i} value first.

Since that would be the worst case for the second player.

Otherwise all of the approaches I've found are *O*(*n*^{2}) ..

Any help is appreciated.

Thanks!

Sort and greedy

.

This problem is equivalent to what Errichto explained in his lecture at minute 29:35 or so. The only diference is that you first sort the array by biggest ai, and break ties by biggest bi (just like you mentioned in your post). Now you know how much each item is worth for you, and you know that the opponent will take always the leftmost item in his turn.

Thanks to VLamarca I now solved it after watching Errichto's video lectures(part 1 and 2) on the "Exchange Argument" technique, although I'm not sure if this method too can fall inside that technique since it's different from the other problems he solved in his stream.

Here is his blog about it, this exact trick is explained in the 6th problem there, in the part 2 video.

Solution.