eolymp
bolt
Try our new interface for solving problems
Problems

Playing with coins

Playing with coins

Coins in denominations of one penny decomposed into stacks (a stack may be a different number of coins), and the stack placed on the table in a row from left to right. Two opponents take turns making moves. Progress lies in the fact that one player takes on the left several piles in a row, no less than one nor more than before that he took his opponent. The first player takes his first move no more than \textbf{K} stacks. The game ends when the cups are left. Required to find the maximum number of coins that can get the first party after the game, if the second player also tries to walk, so to get as many coins. \InputFile The first line is a first number of stacks \textbf{N}, follow him: for \textbf{N} numbers giving the number of coins in the stacks from left to right, then the number of \textbf{K}. All the numbers in the row are separated by spaces. \textbf{1} <= \textbf{N} <= \textbf{180}, \textbf{1} <= \textbf{K} <= \textbf{80}, number of coins in the pile - at least \textbf{1} and not more than \textbf{20 000}. \OutputFile Derive a single number - the maximum number of coins that can certainly get the first player.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3 4 9 1 3
Output example #1
14