#include
using namespace std;
Long long n, bz, s=0, mid, leftt, longest, trees [1000008].
Int main ()
{
The scanf (" % LLD % LLD, & amp; N, & amp; Bz);
for(int i=1; i<=n; I++)
{
The scanf (" % LLD, & amp; Trees [I]);
Longest=Max (longest, trees [I]);//find the longest wood
}
While (leftt<=longest)
{
Mid=(leftt + longest)/2;//start from the middle point as the logging machine height
s=0;
for(int i=1; i<=n; I++)
If (trees [I] & gt; Mid)//height of the tree is greater than the wood cutter height
S +=trees [I] - mid;//high part of the accumulative
If (s
The else
Leftt=mid + 1;//on the right search increase highly reduce the wood
}
Cout
}
CodePudding user response:
The binary search is not from the binary trees, but the height of the binary, namely find maximum height, so leftt from 0 to the maximum height is this order is?CodePudding user response: