Maximize movie ratings

0

0 votes
Sorting, Algorithms, Easy, Greedy
Problem

A movie rating website is hacked to maximize the total rating of a particular show. The hacker decides to flip (negative becomes positive and vice versa) the sign of K ratings. He has to perform exactly K flips on N ratings stored in the database. The flips may or may not be optimal. He can also flip the sign of the same rating more than once.

Write a program to calculate the highest possible total rating of the show.

Input format
First line : Two space-separated integers, N and K
second line : N space-separated integers denoting the ratings

Output format
Print the highest possible rating.

Constraints
1N107
1K107
10Rating10

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

We have 2 flips available,also 2 negative ratings. We flip them and arrive at total rating of (1+1+1+1)=4

Editor Image

?