MemSQL Start[c]UP 3.0 - Round 1
C
Pie Rules
Codeforces
1500
原题
← BD →
翻译中…

You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.

翻译中…

The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.

翻译中…

All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?

翻译中…

Input

翻译中…

Input will begin with an integer $*N*$ ($1 ≤ *N* ≤ 50$), the number of slices of pie.

翻译中…

Following this is a line with $*N*$ integers indicating the sizes of the slices (each between $1$ and $100000$, inclusive), in the order in which they must be handed out.

翻译中…

Output

翻译中…

Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.

翻译中…

Note

翻译中…

In the first example, Bob takes the size $141$ slice for himself and gives the decider token to Alice. Then Alice gives the size $592$ slice to Bob and keeps the decider token for herself, so that she can then give the size $653$ slice to herself.

翻译中…

样例

Input #1
3
141 592 653
Output #1
653 733
InputCopy OutputCopy
Input #2
5
10 21 10 21 10
Output #2
31 41
InputCopy OutputCopy
题目信息
题号
859C
时间限制
2 s
内存限制
256 MB
标签
动态规划
博弈论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。