PS: 浮点数二分。 省赛热省。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
vector<double> v;
int n, k;
double maxv;
bool ok(double x) {
if(dcmp(x-0.01)<0) return false;
int cnt = 0;
int num;
for(int i = 0; i < (int)v.size(); i++) {
num = v[i]/x;
cnt += num;
}
if(cnt>=k) return true;
else return false;
}
double work() {
double l = 0, r = maxv;
double mid;
for(int i = 0; i < 100; i++) {
mid = (l+r)/2;
if(ok(mid)) l = mid;
else r = mid;
}
return mid;
}
int main()
{
double tmp;
while(scanf("%d%d", &n, &k)!=EOF) {
v.clear();
maxv = 0.0;
for(int i = 1; i <= n; i++) {
scanf("%lf", &tmp);
maxv = max(maxv, tmp);
v.push_back(tmp);
}
double res = work();
printf("%.2f\n", floor(res*100)/100.0);
}
return 0;
}