Sweet War
Time limit1sMemory limit256 MB
Two players alternate passing at one energy each or eating the next ball for its nutrition and taste, and each maximizes total taste eaten.
- Level
Hard8 of 10
- Topics
- Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
There are two countries, Imperial Cacao and the Principality of Cocoa. Alice, the Empress of Cacao, and Brianna, the Princess of Cocoa, are friends, and both of them love chocolate.
One day Alice found a transparent tube filled with chocolate balls. The tube has a single opening at its top end, and it is so narrow that the chocolate balls sit in one line. The balls are numbered through . Ball is next to the opening, ball is right below it, and ball is at the bottom of the tube. A ball can leave the tube only through the opening, so the balls must be taken out in increasing order of their numbers.
Alice visited Brianna to share the tube. They looked at the balls carefully and decided that ball has nutrition value and deliciousness . Each of them wants to maximize the total deliciousness of the balls she eats. To settle this peacefully, they play a game with the following rules.
- Alice starts with energy and Brianna starts with energy . Both are nonnegative integers.
- The two players take turns, and on her turn a player takes one of the two actions below.
- Pass: she eats nothing. She gets a little hungry, so her energy level drops by . She cannot pass when her energy level is .
- Eat: she eats the topmost chocolate ball. If that ball is ball , she gains deliciousness and her energy level rises by . Her energy level does not drop by in this case. Ball is removed from the tube.
- Alice takes the first turn.
- The game ends when every chocolate ball has been eaten.
Compute the total deliciousness Alice gets and the total deliciousness Brianna gets when both play optimally.
Input
The input is a single test case in the following format.
N A B
r1 s1
r2 s2
...
rN sN
The first line has three integers , , and . is the number of chocolate balls, and and are the initial energy levels of Alice and Brianna. Each of the next lines describes one ball, from the top of the tube down. The -th of those lines has the nutrition value and the deliciousness of ball .
Output
Print two integers on one line, separated by a space: the total deliciousness Alice gets and the total deliciousness Brianna gets when both play optimally.