Problem1070--Card Game

1070: Card Game

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Alice and Bob are playing a card game. They have a deck of cards with positive integer values. They will play the game in turns. In each turn, the player takes the top card from the deck and adds it to their hand. They will continue playing until the deck is empty.

The goal of the game is to have the highest sum of card values in their hand at the end of the game. However, there is a special rule: If the card's value on the top of the deck is equal to the sum of the last K cards taken, the player must skip his turn and put the card to the bottom of the deck.

Write program to output the final scores of Alice and Bob. (Alice is the first person to play, if there are less than K cards taken, then no special rule should be applied)

Input

The first line has two integers N (the number of cards) and K    ( 1 <= N <= 1000,000,  1 <= K <= N )
the second line contains N integers which are the value of card

Output

two integers , the first one is the final score of Alice and the second one is Bob's final score. 

Sample Input Copy

8 2
5 7 12 4 6 10 16 3

Sample Output Copy

39 24

HINT

Explain for the test case:
Alice takes 5
Bob takes 7
Alice skips 12  (5+7=12) and put 12 to the end of the deck  (4 6 10 16 3 12 )
Bob takes 4
Alice takes 6
Bob skips 10  (16 3 12 10 )
Alice takes 16
Bob takes 3
Alice take 12
Bob takes 10
So Alice is 39 and Bob is 24

Source/Category