QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#6139. Card Game

Statistics

Alice has $n$ cards. The $i$-th card ($1 \le i \le n$) has a number $a_i$ on the front and a number $b_i$ on the back. Initially, all cards are face up.

Alice can flip at most $m$ cards, changing them from face up to face down. Alice's goal is to minimize the range (the difference between the maximum and minimum values) of the $n$ numbers that are face up at the end. Please help Alice calculate the minimum possible range.

Input

The first line contains two positive integers $n$ and $m$, representing the number of cards and the maximum number of cards that can be flipped.

The second line contains $n$ positive integers, where the $i$-th number represents $a_i$.

The third line contains $n$ positive integers, where the $i$-th number represents $b_i$.

It is guaranteed that the $2n$ numbers on the cards are distinct, and the cards are given in ascending order of $a_i$.

Output

A single integer representing the answer.

Examples

Input 1

6 3
8 11 13 14 16 19
10 18 2 3 6 7

Output 1

8

Note 1

One optimal strategy is to flip the 1st, 5th, and 6th cards. The final numbers facing up are 10, 11, 13, 14, 6, 7. The range is $14 - 6 = 8$.

Examples 2

See card/card2.in and card/card2.ans in the contestant directory.

Examples 3

See card/card3.in and card/card3.ans in the contestant directory.

Constraints

For all test data: $3 \le n \le 10^6$, $1 \le m < n$, $1 \le a_i, b_i \le 10^9$.

The specific constraints for each test case are as follows:

Test Case ID $n \le$ Special Constraints
1 ~ 2 10 None
3 ~ 4 500 None
5 ~ 6 $5 \times 10^5$ $m \le 1000$
7 $1 \times 10^5$ None
8 $4 \times 10^5$ None
9 $7 \times 10^5$ None
10 $1 \times 10^6$ None

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.