Jzoj 1724. Eko (eko.pas/cpp)

Source: Internet
Author: User

1724. "10.6NOIP Universal Simulation" Eko (eko.pas/cpp)
(File IO):input: eko.in output: eko.out Time limit:ms Space limit: 256000 KB Specific Restrictions Goto Problemset Title Description

Little X recently did not have to do the work of brick, he became an honorable woodcutter. But loggers are also bad when he has to cut down at least M-m of wood every day. But little X felt no pressure, because Little y had recently bought him a brand-new woodcutter that could destroy the forest like wildfire. But the woodcutter was so big that it could only chop down a whole row of trees at a time.

The loggers work like this: The small x designs a parameter H, and the woodcutter cuts down a row of n trees and then gets the portion of each tree above H. For example, there are 4 trees, the height of 20,15,10,17 meters, and the small x set H to 15 meters. So he got 5m of wood from the first tree, and the fourth tree got 2m of wood, altogether 7m. Of course, if the height of a tree is not greater than H, then it will not be cut down, it will not leave the wood. Little X is an environmentalist who wants H to be as big as possible so that he can cut down as few trees as possible. Of course, the premise is that small x can get at least m m wood. Enter the first line of two integers n,m, which means there are n trees, small x cut at least m m of wood every day.

The second row n integer AI, which represents the height of each tree. outputs an integer that represents the maximum height required. Sample Input
4 7

20 15 10 17
Sample Output
15
data range limit for 30% data: 1≤n≤1 000

For 100% of data:

1≤n≤1 000 000

1≤m≤2 000 000 000

1≤ai≤1

 

PS: The topic should be not impossible, can be ignored

first

.      Suppose there is a height B is the answer we want, then we can draw a formula like this:

        total height and-preserved trees >= at least to get the wood   is

Solution inequality to get:   "the grammar of learning latex is very difficult ... "

      do we just have to solve the B on this inequality?

 ?

Second

   of course not!

   Because this behavior occurs:

third

   Final Solution:

    1.  the An array qsort and evaluates b

   2 from the beginning of the minimum a[1], if B is higher than a[i] then divide the absolute value of their difference to the other tree

 & nbsp;   then compares, until A[i]<=b stops the loop, and the resulting B is a real number, rounding it out, output

  ps:   Pascal's floating-point comparison pits,   Debugging for half an hour, only to find to subtract a 0.9999999....qwq

 

1 {2 by @bobble!3 2017-1-194 }5  ProgramEko;6 Const7inf='eko.in';8outf='Eko.out';9 varTen M:int64; One Sum,ans:qword; A aa,s2:extended; - I,n:longint; -A:Array[0..1000000] ofInt64; the  - procedureqsort (l,r:longint); - var - I,j,x,y:int64; + begin -I:=l;  J:=r; x:=a[(L+r)Div 2]; +    Repeat A       whileA[i]<x DoInc (i); at       whileX&LT;A[J] DoDec (j); -      if  not(I&GT;J) Then -      begin -Y:=a[i];   A[I]:=A[J]; a[j]:=y; -Inc (I); j:=j-1; -      End; in   untilI>J; -   ifL<j Thenqsort (l,j); to   ifI<r Thenqsort (i,r); + End; -  the begin * assign (input,inf); $ assign (OUTPUT,OUTF);Panax Notoginseng reset (input); rewrite (output); -  the readln (n,m); +  A    fori:=1  toN Do the   begin + read (a[i]); -sum:=sum+A[i]; $   End; $Qsort1, n); -  -aa:= (SUM-M)/N; the  -i:=1;Wuyi    whileAa>a[i] Do the   begin -S2:= (aa-a[i]); WuAA:=AA+S2/(ni); - Inc (i); About     ifI>n ThenBreak ; $   End; -   ifTrunc (aa-0.9999999)+1>a[i] Thenans:=trunc (AA) -     ElseAns:=trunc (aa-0.9999999)+1; - writeln (ans); A  + close (input); the close (output); - End.

Jzoj 1724. Eko (eko.pas/cpp)

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.