Problem list
Log in
#coci00522 · COCI 2018/2019 Contest 6

Simfonija

Platinum V 1.0 s 64 MB

Almost no one believed in the virtuous abilities of the composer Marin. Specifically, not until the day he composed his 9th symphony. The symphony can be represented as a series of frequencies that are integer numbers. In order for Marin to prove his talent and demonstrate that this symphony is not just one of many, he decided to compare it with the ancient symphony "Little Night Fiesta" of the best musician in history, Stjepan. In the stars it is written that the lengths of these two symphonies are equal to $N$. Marin compares the symphonies by writing them one under the other to a piece of paper. The symphony diversity is defined as the sum of the absolute differences of the corresponding frequencies. The diversity of symphonies $A$ and $B$ of length $N$ is: ∑ $N$ $i = 1$ $A$ || {i} ^{−B}{i}^{|}| Before comparing the two symphonies, Marin will do two things. First, he will modulate his symphony by adding an integer number $X$ to each frequency. Then he will change no more than $K$ frequencies to some other arbitrary frequency value because he had a vision in the dream as well as every top author. Marin will choose $X$ and change some $K$ frequencies so that his symphony is as similar to Stjepan's, i.e. so the defined diversity is minimal. Help Marin and calculate the smallest possible diversity to Stjepan's symphony.

Input

In the first line there are integer numbers $N$ and $K$ ($1 \le N \le 100,000$, $0 \le K \le N$), numbers from the task's text. In the second line there are $N$ integer $A_{i}$ (-$1,000,000 \le A_{i} \le 1,000,000$) which represent frequencies of Marin's symphony. In the third line there are $N$ integer $B_{i}$ (-$1,000,000 \le B_{i} \le 1,000,000$) which represent frequencies of Stjepan's symphony.

Output

In the only line print out the smallest possible diversity between Marin and Stjepan's symphony.

Constraints

In the test samples totally worth 40% of the points it will hold $K = 0$.

Example 1

Input
3 0

1 2 3

4 5 7


3 1

1 2 3

4 5 7


4 1

1 2 1 2

5 6 7 8
Output
output
output
1


0


2

Clarification of the second sample: If Marin modulates his symphony for X = 3 and changes the last frequency to 7, his symphony will then be

completely equal to Stjepan's, so the required diversity is 0.

Source
COCI 2018/2019 Contest 6
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code