#P16818. [蓝桥杯 2026 国 Python B] 仓库管理

[蓝桥杯 2026 国 Python B] 仓库管理

Problem Description

Xiao Lan is a warehouse manager at a large logistics center. Today, the system issued an urgent task: all NN standard containers must be stored in the warehouse and assigned to MM shelves.

The shelves are numbered from left to right as 1,2,,M1, 2, \dots, M. Because the distance for the automated robotic arm to deliver a container to different shelves varies, placing 11 container onto shelf ii costs ii units of electricity.

The company requires that the total electricity cost of this storage task must lie within the closed interval [L,R][L, R]. At the same time, to avoid any single shelf bearing too much weight, Xiao Lan wants the shelf that holds the most containers to hold as few as possible.

Formally, you need to construct a non-negative integer sequence a1,a2,,aMa_1, a_2, \dots, a_M, where aia_i denotes the number of containers placed on shelf ii. The sequence must satisfy:

  • All containers are assigned to shelves, i.e., i=1Mai=N\sum_{i=1}^{M} a_i = N.
  • The total electricity cost satisfies Li=1Mi×aiRL \le \sum_{i=1}^{M} i \times a_i \le R.

Among all valid assignment plans, output the minimum possible value of max(a1,a2,,aM)\max(a_1, a_2, \dots, a_M). If no valid plan exists, output 1-1.

Input Format

The input consists of one line containing four integers N,M,L,RN, M, L, R, representing the number of containers, the number of shelves, the lower bound of the total electricity cost, and the upper bound of the total electricity cost.

Output Format

Output one line containing one integer, the minimum possible value of max(ai)\max(a_i).

If no valid plan exists, output 1-1.

5 3 13 14
3

Hint

Sample Explanation

The following two plans both satisfy the total electricity cost constraint:

  • a1=0,a2=2,a3=3a_1 = 0, a_2 = 2, a_3 = 3, with total electricity cost 0×1+2×2+3×3=130 \times 1 + 2 \times 2 + 3 \times 3 = 13, and max(ai)=3\max(a_i) = 3.
  • a1=0,a2=1,a3=4a_1 = 0, a_2 = 1, a_3 = 4, with total electricity cost 0×1+1×2+4×3=140 \times 1 + 1 \times 2 + 4 \times 3 = 14, and max(ai)=4\max(a_i) = 4.

The first plan has a smaller maximum number of containers on any shelf. It can be proven that there is no valid plan with max(ai)\max(a_i) less than 33, so the answer is 33.

Constraints

For 40%40\% of the testdata, it is guaranteed that N,M40N, M \le 40.

For all testdata, it is guaranteed that 1N,M200001 \le N, M \le 20000 and 1LRNM1 \le L \le R \le NM.

Translated by ChatGPT 5