BZOJ 2600: [Ioi2011]ricehub

Source: Internet
Author: User
Tags cmath

2600: [Ioi2011]ricehub time limit:10 Sec Memory limit:128 MB
submit:628 solved:325
[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.


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


An integer maximum number of rice

Sample Input
5 20 6
Sample Output
1≤l≤1,000,000,0000≤b≤2,000,000,000,000,000 This topic actually in our school lectures is classified for two points (not serious lectures qaq do not know how magnetic AH) percent is obviously easy to draw our chosen Yonekura must collect a continuous interval, and Yonekura must be in this intervalNumber of medianOn We will right interval R from 1 to R enumeration, each maintenance of the left interval L. Remember res for the remaining amount of money. If res is less than 0, the left interval shifts to the right (that is, the queue is the first to queue) until Res is greater than 0. The median can be transferred by O (1). About complexity: Because each paddy field is up to two operations per queue and team, the complexity is O (n)
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cmath>5#include <algorithm>6#include <cmath>7#include <queue>8 #defineLLG Long Long9 #defineYyj (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout);Ten #defineMAXN 100010 One using namespacestd; A  - Llg SC () - { theLLG i=0;CharC=GetChar (); -      while(c>'9'|| c<'0') c=GetChar (); -      while(c>='0'&&c<='9') i=i*Ten+c-'0', c=GetChar (); -     returni; + } -  + LLG X,i,j,k,n,l,r,mid,m,a[maxn],ans; A DoubleRes,b,wz,lastwz; at intMain () - { -Yyj"a"); -Cin>>n>>m>>b; -      for(i=1; i<=n;i++) a[i]=SC (); -res=b; inx=1;  -ans=1;  toL=0; lastwz=a[1]; +      for(r=2; r<=n;r++) -         { the             if(a[r]>m) Break; *X + +; $             if(x%2) wz=a[l+x/2+1];ElseWz= (Double) (a[l+x/2]+a[l+x/2+1])/2;Panax Notoginseng             if(x%2==0) res-= (wz-lastwz); -RES-=A[R]-WZ; lastwz=wz; the              while(res<0) +                 { Ax--; l++; res+=lastwz-A[l]; the                     if(x%2) wz=a[l+x/2+1];ElseWz= (a[l+x/2]+a[l+x/2+1])/2; +                     if(x%2) res+=wz-Lastwz; -lastwz=wz; $                 } $ans=Max (ans,x); -         } -cout<<ans; the     return 0; -}

BZOJ 2600: [Ioi2011]ricehub

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: 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.