P27584 [洛谷] [Language Monthly Contest 202208] Array Adjustment
普及-
题目描述

Problem Description

Given an array of length $n$, where the $i$-th element is $a_i$.

To adjust this array, the $k$-th element needs to be changed to $-a_k$.

Please calculate the sum of all elements in the adjusted array.

Input Format

The input consists of two lines.

The first line contains two integers $n$ and $k$.

The second line contains $n$ integers, where the $i$-th integer is $a_i$.

Output Format

Output a single integer, which is the sum of all elements in the adjusted array.

Sample Input and Output

Sample Input #1

10 7
1 2 3 4 5 6 7 8 9 10

Sample Output #1

41

Sample Input #2

5 2
1 999 4 3 2

Sample Output #2

-989

Sample Input #3

10 2
1 0 1 1 1 1 1 1 1 1

Sample Output #3

9

Notes

Explanation of Sample Input/Output 1

The adjusted array is 1 2 3 4 5 6 -7 8 9 10, and the sum is 41.

Explanation of Sample Input/Output 2

The adjusted array is 1 -999 4 3 2, and the sum is -989.

Data Size and Constraints

For $5\%$ of the data, it corresponds to Sample Input/Output 1.

For another $40\%$ of the data, the element to be adjusted, $a_k$, is 0.

For another $20\%$ of the data, $k = 1$.

For $100\%$ of the data, $1 \le k \le n$, $n \le 10^6$, and $0 \le a_i \le 10^9$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
10 7 1 2 3 4 5 6 7 8 9 10
样例输出
41