#B4468. 符号选择 / opt
符号选择 / opt
Problem Description
Given a sequence of natural numbers .
Now, assign either a positive sign () or a negative sign () to each number in the sequence, and then compute the sum.
Specifically, among the numbers, exactly numbers must use the positive sign, and the remaining numbers must use the negative sign.
Determine the maximum possible sum that can be obtained through this operation.
Input Format
The first line contains two integers and , representing the length of the sequence and the required number of positive signs, respectively.
The second line contains natural numbers , representing the given sequence. It is guaranteed that .
Output Format
A single line containing an integer, representing the maximum possible sum that can be obtained.
3 2
5 2 1
6
Hint
[Constraints]
For of the data, .
For another of the data, .
For another of the data, all are equal.
For of the data, , .
Translated by DeepSeek-V3