Robot
InterviewTime limit2sMemory limit512 MB
Given a sequence of signed step sizes, flip at most k signs to maximize the absolute value of the final position.
Problem
The company <> sent a new robotic rover to Mars. The robot's goal is to explore the surface of Mars.
To explore Mars, the robot travels along the planet's surface north and south in a straight line. The robot's program consists of commands, each described by an integer . Each number specifies the number of steps the robot must take. If , the robot takes steps north; if , it takes steps south. The robot executes the commands in order, starting with the first.
However, on the way to Mars the robot was exposed to cosmic radiation and its program may have been corrupted. After running a memory test procedure, the scientists found that between 0 and errors of the following form were introduced into the program: a number was replaced by . Nevertheless, after landing on Mars, the robot executed its possibly corrupted program.
Now, to organize the robot's rescue, the scientists want to find out how far from the point where it began executing the program the robot could have ended up. Help them find this out.
Input
The first line of the input file contains two numbers , (): the number of numbers in the robot's program and the maximum number of errors.
The second line of the input file contains numbers (, ): the robot's program.
Output
In a single line of the output file, output the maximum distance in steps by which the robot could have moved away after executing all commands and making at most errors.
Hint
In the first example, the robot could, for instance, execute the program and end up 5 steps north.