This page is still under construction.

Parts of this page are still being built. What you see may change.

Robot

Interview

Time limit2sMemory limit512 MB

Summary
Given a sequence of signed step sizes, flip at most k signs to maximize the absolute value of the final position.
Level

Medium6 of 10

Topics
Greedy, Sorting, Math, Array
Solved
No attempts yet

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 nn commands, each described by an integer aia_i. Each number aia_i specifies the number of steps the robot must take. If ai>0a_i > 0, the robot takes ∣ai∣|a_i| steps north; if ai<0a_i < 0, it takes ∣ai∣|a_i| 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 kk errors of the following form were introduced into the program: a number aia_i was replaced by −ai-a_i. 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 nn, kk (1≤k≤n≤1051 \le k \le n \le 10^5): the number of numbers in the robot's program and the maximum number of errors.

The second line of the input file contains nn numbers aia_i (−104≤ai≤104-10^4 \le a_i \le 10^4, ai≠0a_i \ne 0): 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 kk errors.

Hint

In the first example, the robot could, for instance, execute the program 1,2,−1,31, 2, -1, 3 and end up 5 steps north.

Examples2

  1. Example 1

    Input
    4 1
    1 2 -1 -3
    
    Expected output
    5
    
  2. Example 2

    Input
    7 2
    5 -3 7 9 -2 -8 -1
    
    Expected output
    29