Petra and Jan have just received a box full of free goodies, and want to divide the goodies between them. However, it is not easy to do this fairly, since they both value different goodies differently.

To divide the goodies, they have decided upon the following procedure: they choose goodies one by one, in turn, until all the goodies are chosen. A coin is tossed to decide who gets to choose the first goodie.

Petra and Jan have different strategies in deciding what to choose. When faced with a choice, Petra always selects the goodie that is most valuable to her. In case of a tie, she is very considerate and picks the one that is least valuable to Jan. (Since Petra and Jan are good friends, they know exactly how much value the other places on each goodie.)

Jan's strategy, however, consists of maximizing his own final value. He is also very considerate, so if multiple choices lead to the same optimal result, he prefers Petra to have as much final value as possible.

You are given the result of the initial coin toss. After Jan and Petra have finished dividing all the goodies between themselves, what is the total value of the goodies each of them ends up with?

有两个人，分N个物品，每个物品分别对两个人有不同的价值。两个人每次轮流从未被拿走的物品中拿走一个物品。规则是第一个人每次是拿剩下物品中对他而言价值最高的那个，如果有相同的就会拿那个对另外一个人价值最低的物品。另一个人是每次拿那个能保证他最后能拿到价值最大的物品，当然如果有多种选项的话也会优先选择那个对另外一个人价值最低的物品。现在告诉你物品和谁先拿，问最后两人分别能拿到多少？