题解(不过大家为什么都抄练习记录?)
2024-08-28 16:27:47
发布于:广东
2阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
long long n,k;
bool check(long long mid){
long long sum = 0;
for(int i = 0;i < n;i ++){
sum += a[i] / mid;
}
if(sum >= k){
return true;
} else {
return false;
}
}
int main(){
int max = 0;
long long g = 0;
double x;
cin >> n >> k;
for(int i = 0;i < n;i ++){
cin >> x;
a[i] = x * 100;
if(a[i] > max){
max = a[i];
}
g += a[i];
}
long long l = 1,r = max,mid,ans = 0;
if(g < k){
cout << 0;
return 0;
}
while(l <= r){
mid = (l + r) / 2;
if(check(mid)){
l = mid + 1;
ans = mid;
} else {
r = mid - 1;
}
}
double ans1 = ans / 100.0;
printf("%.2f",ans1);
return 0;
}
这里空空如也
有帮助,赞一个