Lydsy 2600 (two-digit + median prefix and) Yonekura

Source: Internet
Author: User

2600: [Ioi2011]ricehub time limit:10 Sec Memory limit:128 MB
submit:691 solved:359
[Submit] [Status] [Discuss] Description

There is a straight and long road in the country called the "Rice Road". Along this rice path, R blocks of paddy fields, the coordinates of each paddy field are
is an integer between 1 and L (with 1 and L). These paddy fields are given in the order of the coordinates in a non-decreasing sequence, i.e. for 0≤i <
R, paddy field I coordinates x[i] meet 1≤x[0]≤ ... ≤x[r-1]≤l.
Note: There may be more than one paddy field at the same coordinate.
We plan to build a Yonekura to store as much rice as possible. Like paddy fields, Yonekura will be built on the Rice road, and its
The coordinates are also an integer between 1 and L (with 1 and L). This yonekura can be built on any bit that satisfies the above conditions
, including those where one or more rice fields have existed.
In the harvest season, every paddy field produces just one wagon of rice. In order to transport these rice to Yonekura, it is necessary to hire
Use a lorry driver to transport rice. The driver's charge is $1 for each full lorry transporting a unit. In other words,
The cost of transporting rice from a particular paddy field to the Yonekura is numerically equal to the absolute value of the difference between the field coordinates and the Yonekura coordinates.
Unfortunately, this year's budget is limited, we can only spend B yuan freight. Your mission is to help us find a
Build a Yonekura location where you can collect as much rice as possible.

Input

First row three integers R L B
Next, an integer for each line of the R line represents X[i]

Output


An integer maximum number of rice

Sample Input
5 20 6
1
2
10
12
14
Sample Output
3
HINT
1≤r≤100,000
1≤l≤1,000,000,000
0≤b≤2,000,000,000,000,000HINT

Source

varI,j:longint, R,l,ans,num,x,y,mid,b,n:int64, a,f:array[0..200000] of int64;function PD (Mid:int64): boolean;vari,j:longint; M,sum:int64;begin fori:=1To n-mid+1  Dobegin J:=i+mid-1; M:= (i+j) div2; Sum:=f[j]+f[i-1]-f[m]-f[m-1]+a[m]* (M-i)-a[m]* (J-m); //The most important sentence (note)   ifSum<=b Then Exit (true); End Exit (false); End;begin readln (N,Y,B);  fori:=1to n Dobegin Read (A[i]); F[i]:=f[i-1]+A[i]; End L:=1; r:=N; whileR>=l Dobegin Mid:= (r+l) div2; ifPD (mid) THEN begin ans:=mid; L:=mid+1; EndElser:=mid-1; End Writeln (ans); end.

Lydsy 2600 (two-digit + median prefix and) Yonekura

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.