#P7514. [省选联考 2021 A/B 卷] 卡牌游戏
[省选联考 2021 A/B 卷] 卡牌游戏
Description
Alice has cards. On the front of the -th card () there is a number , and on the back there is a number . Initially, all cards are face up.
Now Alice may flip at most cards, changing them from face up to face down. Alice’s goal is to make the range (the difference between the maximum and minimum) of the numbers showing in the end as small as possible. Please help Alice compute the minimum possible range.
Input Format
The first line contains two positive integers , representing the number of cards and the maximum number of cards that may be flipped.
The second line contains positive integers; the -th number is .
The third line contains positive integers; the -th number is .
The testdata guarantees that all numbers on the cards are pairwise distinct, and the cards are given in increasing order of .
Output Format
Only one line, an integer, indicating the answer.
6 3
8 11 13 14 16 19
10 18 2 3 6 7
8
见附件中的 card/card2.in。
见附件中的 card/card2.ans。
见附件中的 card/card3.in。
见附件中的 card/card3.ans。
Hint
[Sample #1 Explanation]
One optimal plan: flip cards . The numbers showing in the end are, in order, , and the range is .
[Constraints]
For all testdata: , , .
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Constraint | |
|---|---|---|
| None. | ||
| . | ||
| None. | ||
Translated by ChatGPT 5
京公网安备 11011102002149号