cswork / OAOpen practice workspace

LinkedInOA #5

Get Process Time

Estimated MediumJudge-ready

Topics (AI-labelled)Tree & Game DP

Assign each process in the original order. The core holding the lock can either give the current process to itself and hand over the lock, or give it to the other core and keep the lock; both sides maximize their own final total time, and core 1 initially holds the lock.

Input

The first line contains n, and the second line contains n values of time. The original bounds 1≤n≤100000 and 1≤time[i]≤10^9 are restored from Millennium's same-problem OCR001..004; the operation applies to the current i-th item, and the original Fastprep's i+1 is a typo. Output two exact integers.

Output

Output the total processing times of core 1 and core 2, one integer each.

Example 1

Input:

5
10 21 10 21 10

Output:

41 31

Example 2

Input:

4
10 10 10 10

Output:

20 20

Example 3

Input:

1
7

Output:

7 0

Example notes

The outputs of the three public examples are, in order: 41 31; 20 20; 7 0. Checked by independent enumeration or direct simulation.

Editorial

Loading solution…