传送门
思路:
用二分对答案mid进行枚举,若按照当前mid进行切割可获得的长度大于k,则l = mid+0.0001,否则r = mid-0.0001,最后用floor向下取整;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
double a[1000010];
int n,m;
bool check(double x)
{
int cnt = 0;
for(int i = 1; i <= n; i++)
{
cnt += (a[i] / x);
}
return cnt >= m;
}
int main()
{
cin>>n>>m;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
}
double l = 0.0,r = 100010.0;
while(l-r<0.0001)
{
double mid = (l+r)/2;
if(check(mid))
{
l = mid+0.0001;
}
else
{
r = mid-0.0001;
}
}
printf("%0.2lf\n",floor(l*100)*1.0/100.0);
}