#P5844. [IOI 2011] ricehub

[IOI 2011] ricehub

Description

In the countryside, there is a straight and long road called the “Rice Road”. Along this Rice Road there are RR rice fields, and the coordinate of each field is an integer between 11 and LL (including 11 and LL). These fields are given in non-decreasing order of coordinates, that is, for 0i<R0 \le i < R, the coordinate X[i]X[i] of field ii satisfies 1X[0]X[R1]L1 \le X[0] \le \cdots \le X[R-1] \le L.

Note: multiple fields may be located at the same coordinate.

We plan to build a rice hub to store as much rice as possible. Like the rice fields, the hub will be built on the Rice Road, and its coordinate is also an integer between 11 and LL (including 11 and LL). The hub can be built at any position that satisfies the above conditions, including positions where one or more rice fields already exist.

During harvest season, each rice field produces exactly one full truckload of rice. To transport this rice to the hub, we need to hire a truck driver. The driver charges 11 yuan per unit distance for each full truckload. In other words, the cost to transport rice from a particular field to the hub equals the absolute difference between the field’s coordinate and the hub’s coordinate.

Unfortunately, this year the budget is limited, and we can spend at most BB yuan on transportation. Your task is to help us find a hub location that can collect as much rice as possible.

Input Format

The first line contains three integers R,L,BR, L, B.

The next RR lines each contain one integer, representing X[i]X[i].

Output Format

Output one integer, the maximum amount of rice that can be collected.

5 20 6
1
2
10
12
14
3

Hint

For 100%100\% of the testdata, 1R1051 \le R \le 10^5, 1L1091 \le L \le 10^9, 0B2×10150 \le B \le 2 \times 10^{15}.

Translated by ChatGPT 5