Luogu 1873

Core perception :

①: about check() function : Once this judgment function related to calculating the sum ——sum=0 Be sure to write it in front

②: Because the answer of binary search can be huge , Just use it all long long

Thought of judgment :

 ①: principal axis : It's the line between the answer and the scope , Such as the height of saw blade , The side length of the divided cake .

 ②: Countershaft : The variable required .
#include<bits/stdc++.h> using namespace std; long long l=1,r=9e9; long long
sum=0;long long ans; long long n,k; bool check(long long arry[],long long m) {
sum=0; for(int i=1;i<=n;i++) { if(m<arry[i]) { sum+=arry[i]-m; } }
if(sum>=k)return 1; return 0; } int main() { scanf("%lld%lld",&n,&k); long long
arry[n+1]; for(int i=1;i<=n;i++)scanf("%lld",&arry[i]); while(l<=r) { long long
m=l+(r-l)/2; if(check(arry,m)) { ans=m; l=m+1; } else r=m-1; }
printf("%lld",ans); return 0; }

Luogu 2440

Where I write wrong :

while Core code in the loop r=m+1 and l=m-1 Something went wrong .( It's written backwards )

Forget to write while Code snippet inside int m=l+(r-l)/2;( It was discovered after debugging )