BC#34 1002 Hdu 5192 Building Blocks

Source: Internet
Author: User

Building BlocksTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 6


Problem Descriptionafter enjoying the Movie,lele went home alone. LeLe decided to build blocks.
LeLe has already built n Piles. He wants to move some blocks to make W Consecutive piles with exactly the same height H .

LeLe already put all of him blocks in these piles, which means he can not add any blocks into them. Besides, he can move a block from one pile to another or a new one,but not the position betweens both piles already exists. For Instance,after one Move, "3 2 3" can become "2 2 4" or "3 2 2 1", and not "3 1 1 3".

You is request to calculate the minimum blocks should LeLe move.
Inputthere is multiple test cases, about - Cases.

The first line of input contains three integers N,W ,H (1≤N,W ,H ≤50000) . n Indicate n Piles blocks.

For the next line, there is n Integers A 1 , A 2 , A 3 ,... ..... .., A n Indicate the height of each piles. (1≤A i ≤ 50000 )

The height of a block is 1.
Outputoutput the minimum number of blocks should LeLe move.

If There is no solution, output "1" (without quotes).
Sample Input
4 3 21 2 3 54 4 41 2 3 4

Sample Output
1-1Hintin first case, LeLe move one block from third pile to first pile.

Sourcebestcoder Round #34
Recommendhujie | We have carefully selected several similar problems for you:5193 5192 5190 5189 5188
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <    Cstdlib> #define INF 1010010101000#define ll long longusing namespace Std;int n,m,h;ll a[50020*3];ll mmin (ll a,ll b) {    if (a>b) return B; return A;}    ll Mmax (ll A,ll b) {if (a<b) return B; return A;}        int main () {while (cin>>n>>m>>h) {ll sum=0;        for (int i=1; i<=m; i++) a[i]=0;            for (int i=m+1; i<=m+n; i++) {scanf ("%i64d", &a[i]);        Sum+=a[i];        } for (int i=m+n+1; i<=n+m+m; i++) a[i]=0;        ll Ans=0;        if (sum< (LL) h*m) printf (" -1\n");            else {int first=1;            ll Min=inf;            ll Ans1=0;            ll Ans2=0;                for (int i=1; i<=m; i++) {if (a[i]>h) ans1+=a[i]-h;            else Ans2+=h-a[i];            } ans=max (ANS1,ANS2);    Min=ans;        for (int i=m+1; i<=m+m+n; i++) {if (a[first]>h) ans1-=a[first]-h;                else Ans2-=h-a[first];                if (a[i]>h) ans1+=a[i]-h;                else Ans2+=h-a[i];                first++;                Ans=mmax (ANS1,ANS2);            Min=mmin (ans,min);        } cout<<min<<endl; }    }}

BC#34 1002 Hdu 5192 Building Blocks

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.