#P9064. [yLOI2023] 苦竹林

[yLOI2023] 苦竹林

Background

The wind chimes hanging under the eaves sound pleasant as they sway.
Longing is like the endless plum rain, leaving my mood a muddy mess.
The scattered stars across the sky sparkle with the fate we share.
When maple leaves lightly fall into the heart of the lake, the nearby view is calm and peaceful.

— Yin Lin & Han Yu, Bitter Bamboo Grove

Problem Description

There are nn wind chimes hanging under the eaves, and each wind chime can produce a sound of a certain pitch. Number the wind chimes from left to right from 11 to nn. The pitch of the ii-th wind chime is aia_i.

To express his longing, Fusu decides to take mm out of the nn wind chimes and give them to a friend far away.

Please find the minimum integer ε\varepsilon such that there exists a way to choose mm wind chimes from the nn wind chimes. Let the pitches of the selected wind chimes be b1,b2,,bmb_1, b_2, \dots, b_m. They must satisfy that for any 1i,jm1 \leq i, j \leq m, we have bibjε|b_i - b_j| \leq \varepsilon.

Input Format

The first line contains two integers, representing the number of wind chimes nn and the number of wind chimes to select mm.
The second line contains nn integers, representing the pitch of each wind chime. The ii-th integer is aia_i.

Output Format

Output one integer on a single line, representing the minimum ε\varepsilon.

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

Hint

Explanation for Sample 2

One possible plan is to choose the 2,4,5,62, 4, 5, 6-th wind chimes, with pitches 7,3,4,67, 3, 4, 6 in order. Then for any 1i,j41 \leq i, j \leq 4, we have bibj4|b_i - b_j| \leq 4.

Another plan is to choose the 2,3,5,62, 3, 5, 6-th wind chimes. The computed ε\varepsilon is also 44.

Constraints

  • For 10%10\% of the testdata, m=2m = 2.
  • For another 10%10\% of the testdata, m=nm = n.
  • For 40%40\% of the testdata, n5n \leq 5.
  • For 60%60\% of the testdata, it is guaranteed that for all 2in2 \leq i \leq n, ai1aia_{i - 1} \leq a_i, i.e., aia_i is non-decreasing.
  • For 80%80\% of the testdata, n103n \leq 10^3.
  • For 100%100\% of the testdata, 2mn1052 \leq m \leq n \leq 10^5, and 1ai1091 \leq a_i \leq 10^9.

Notes

This problem provides three additional sample files. See ring.zip in the attachments.

Translated by ChatGPT 5