#P15237. [NHSPC 2025] 郵局

[NHSPC 2025] 郵局

Description

There are nn towns located on a straight road. The coordinate of the ii-th town is xix_i. The distance between two towns is defined as the absolute difference of their coordinates.

It is planned to set up post offices in kk towns. After the post offices are built, some of them may be temporarily closed. The goal is to make the distance from every town to the nearest operating post office as small as possible.

Specifically, for the residents of the ii-th town, their "safety tolerance" is an integer sis_i. No matter which sis_i post offices are closed, they still want to be able to go to some operating post office nearby. Let did_i be the distance from this town to the nearest operating post office in the worst-case scenario where at most sis_i post offices are closed. Our objective is to minimize the maximum did_i among all towns.

Input Format

$$\begin{aligned} & n\ \ k \\ & x_1\ \ s_1\ \ \dots\ \ x_n\ \ s_n \end{aligned}$$
  • nn is the number of towns.
  • kk is the number of post offices to be built.
  • xix_i and sis_i are the coordinate and safety tolerance of the ii-th town, respectively.

Output Format

a\begin{aligned} a \end{aligned}
  • aa is the minimum possible value of max1indi\max_{1 \leq i \leq n} d_i under the optimal construction plan.
4 3
1 2 3 1 4 1 6 1
3
5 2
1 0 15 0 4 0 10 0 6 0
5

Hint

Constraints

  • 2n1062 \le n \le 10^6.
  • 1kn1 \le k \le n.
  • 0si<k0 \le s_i < k.
  • 1xi1091 \le x_i \le 10^9.
  • All input values are integers.

Scoring

This problem consists of five subtasks with the following additional constraints.
Each subtask may contain one or more test cases. You must solve all test cases in a subtask to receive its score.

Subtask Score Additional Constraints
1 4 n1000n \le 1000, k=1k = 1.
2 19 n1000n \le 1000.
3 17 n105n \le 10^5, xi106x_i \le 10^6, si=0s_i = 0.
4 33 n105n \le 10^5, xi106x_i \le 10^6.
5 27 No additional constraints.