P29609 [洛谷] [COCI2018-2019#6] Symphony
提高-
题目描述

Problem Description

Given arrays \( A \) and \( B \) each containing \( N \) elements. Add an integer \( X \) to all elements in array \( A \) and modify no more than \( K \) elements to minimize the following algebraic expression:

\[ \sum_{i=1}^N |A_i - B_i| \]

Input Format

The first line contains two integers \( N \) and \( K \).

The second line contains \( N \) integers \( A_i \).

The third line contains \( N \) integers \( B_i \).

Output Format

Output the minimum value of the algebraic expression after the operations.

Sample Input and Output

Sample Input #1

3 0
1 2 3
4 5 7

Sample Output #1

1

Sample Input #2

3 1
1 2 3
4 5 7

Sample Output #2

0

Sample Input #3

4 1
1 2 1 2
5 6 7 8

Sample Output #3

2

Notes

Sample 2 Explanation

When \( X = 3 \) is chosen and the last number in array \( A \) is changed to 7, both arrays \( A \) and \( B \) become identical, resulting in the algebraic expression value of 0.

Data Size and Constraints

For 40% of the data, \( K = 0 \).

For 100% of the data, \( 1 \le N \le 10^5 \), \( 0 \le K \le N \), \( -10^6 \le A_i, B_i \le 10^6 \).

Note

This problem's score is set according to the original COCI contest, with a maximum score of 110.

The problem is translated from COCI2018-2019 CONTEST #6 T4 Simfonija.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 0 1 2 3 4 5 7
样例输出
1