문제1563--BagsOfGold

1563: BagsOfGold

실행시간 제한: 1 Sec  메모리사용 제한: 128 MB
제출: 154  통과: 60
[제출] [채점기록] [묻고답하기]

문제 설명

My partner and I have bags of gold, lined up in a row. The bags are different sizes. My partner has offered to split up the gold using the following system: we take turns, each time choosing one bag from either end of the line. She has even generously offered to let me go first -- hmmmmmmmm....
I need software to tell me the total amount of gold that I will get compared to how much my partner will get if I choose first. Of course we will assume that my partner and I are brilliant and always choose in the optimum way.

입력 설명

The first line of the input gives a number of test cases, T (1 <= T <= 200).
The first line of each case gives a number of bags, N (1 <= N <= 50).
Next line gives N integers, the number of gold in each bag, separated by space. The number of gold in each bag is not greater than 100,000.

출력 설명

For each test case, output the number how much more gold I will get than my partner.

입력 예시 Copy

2
2
7 2
3
2 7 3

출력 예시 Copy

5
-2

출처/분류