#P16227. [蓝桥杯 2026 省 A] 切割木材

[蓝桥杯 2026 省 A] 切割木材

Problem Description

In the corner, an old automatic sorting machine is making a dull roaring sound.

Xiao Lan is standing by the assembly line, ready to feed a batch of wood into the machine. The distance between the machine’s baffles, LL, is the only adjustable parameter. Any wood piece longer than LL will cause the conveyor belt to jam. Clearly, the smaller the baffle distance is, the higher the transport density per unit time will be. Therefore, Xiao Lan wants to set the baffle distance LL as small as possible.

There are NN original logs. The length of the ii-th log is AiA_i. Xiao Lan can cut these logs to meet the length requirement, but due to saw blade wear, he can make at most KK cuts in total. The cutting rules are as follows:

  1. Each cut can split one log into two pieces.
  2. After splitting, the two new pieces must have positive integer lengths, and their sum must equal the length of the original log.

Now, please find the minimum feasible baffle distance LL for Xiao Lan, such that with no more than KK total cuts, after cutting, the maximum length among all wood pieces does not exceed LL.

Input Format

The first line contains two integers NN and KK, representing the number of original logs and the maximum number of cuts.

The second line contains NN integers A1,A2,…,ANA_1, A_2, \ldots, A_N, representing the length of each original log.

Output Format

Output one integer, representing the minimum feasible baffle distance LL.

1 1
5
3
2 3
9 6
3

Hint

Constraints

For 10%10\% of the testdata, 1≤N≤1001 \le N \le 100, 0≤K≤30 \le K \le 3, 1≤Ai≤1031 \le A_i \le 10^3.

For 50%50\% of the testdata, 1≤N≤1031 \le N \le 10^3, 0≤K≤1050 \le K \le 10^5, 1≤Ai≤1051 \le A_i \le 10^5.

For 100%100\% of the testdata, 1≤N≤1061 \le N \le 10^6, 0≤K≤1090 \le K \le 10^9, 1≤Ai≤1091 \le A_i \le 10^9.

Translated by ChatGPT 5