#P1873. [COCI 2011/2012 #5] EKO / 砍树
[COCI 2011/2012 #5] EKO / 砍树
Description
Lumberjack Mirko needs to cut meters of wood. This is easy for Mirko because he has a shiny new woodcutting machine that can cut through a forest like wildfire. However, Mirko is allowed to cut only one row of trees.
The machine works as follows: Mirko sets a height parameter (in meters), the machine raises a huge saw blade to height , and it cuts off the part of every tree that is higher than (of course, trees not higher than remain unchanged). Mirko then collects the cut-off parts. For example, if a row of trees has heights and , and Mirko raises the blade to meters, after cutting the remaining heights will be and , and Mirko will get meters from the st tree and meters from the th tree, meters in total.
Mirko cares about the environment, so he will not cut more wood than necessary. This is why he sets the saw blade as high as possible. Help Mirko find the maximum integer height such that the amount of wood he obtains is at least meters. In other words, if he raised it by meter more, he would not obtain meters of wood.
Input Format
The first line contains two integers and , where is the number of trees and is the required total length of wood.
The second line contains integers, the heights of the trees.
Output Format
Output a single integer, the highest possible blade height.
4 7
20 15 10 17
15
5 20
4 42 40 26 46
36
Hint
For of the testdata, , , tree height , and the sum of all tree heights .
Translated by ChatGPT 5
京公网安备 11011102002149号