[USACO10JAN] Taking Turns G

题目描述

Farmer John has invented a new way of feeding his cows. He lays out N (1 <= N <= 700,000) hay bales conveniently numbered 1..N in a long line in the barn. Hay bale i has weight W\_i (1 <= W\_i <= 2,000,000,000). A sequence of six weights might look something like: 17 5 9 10 3 8 A pair of cows named Bessie and Dessie walks down this line after examining all the haybales to learn their weights. Bessie is the first chooser. They take turns picking haybales to eat as they walk (once a haybale is skipped, they cannot return to it). For instance, if cows Bessie and Dessie go down the line, a possible scenario is: \* Bessie picks the weight 17 haybale \* Dessie skips the weight 5 haybale and picks the weight 9 haybale \* Bessie picks the weight 10 haybale \* Dessie skips the weight 3 haybale and picks the weight 8 haybale Diagrammatically: Bessie | | 17 5 9 10 3 8 Dessie | | This scenario only shows a single skipped bale; either cow can skip as many as she pleases when it's her turn. Each cow wishes to maximize the total weight of hay she herself consumes (and each knows that the other cow has this goal). Furthermore, a cow will choose to eat the first bale of hay that maximimizes her total weight consumed. Given a sequence of hay weights, determine the amount of hay that a pair of cows will eat as they go down the line of hay. 两头奶牛 Bessi 和 Dessie 走过一条路吃草,共 $n(1\le n \le 7\times 10 ^ 5)$ 个格子,第 $i$ 个格子有重量为 $W_i(1 \le W_i \le 2 \times 10 ^{9})$ 的草,两牛轮流走,一旦某头牛走过了一格,那么这格的草再也不可能被任一头奶牛吃,每格的草只能被吃一次,所以两头牛只能往后走。Bessi 先走,每头牛每次都往最终自己能吃到最多草的格子走(若有多个格子则选择第一个能吃到最多草的格子),他们都知道对方也想吃到最多的草,问最后 Bessi 和 Dessie 各吃到的草的重量。 输入格式: 第一行一个正整数 $n(1\leq n\le 7\times 10 ^ 5)$,接下来有 $n$ 行,第 $i+1$ 行为 $W_i(1 \le W_i \le 2 \times 10 ^{9})$。

输入输出格式

输入格式


\* Line 1: A single integer: N \* Lines 2..N+1: Line i+1 contains a single integer: W\_i

输出格式


\* Line 1: Two space-separated integers, the total weight of hay consumed by Bessie and Dessie respectively

输入输出样例

输入样例 #1

6 
17 
5 
9 
10 
3 
8 

输出样例 #1

27 17