49分,求调
查看原帖
49分,求调
1483497
Cc24110906楼主2025/1/19 18:27
#include<bits/stdc++.h>
using namespace std; 
double n,k,a[100010],maxn,l,r,mid,ans;
long long sum;
int check(double mid){
	int num=0;
	for(int i=1;i<=n;i++){
		num=num+(a[i]/mid);
	}
	if(num>=k)
		return 1;
	else
		return 0;
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		maxn=max(maxn,a[i]);
		sum=sum+a[i];
	}
	if(sum<k){
		cout<<0;
		return 0;
	}
	l=1,r=maxn;
	while(l<=r){
		mid=l+(r-l)/2;
		if(check(mid)==1){
			ans=mid;
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	cout<<fixed<<setprecision(2)<<1.0*ans;
	return 0;
}
2025/1/19 18:27
加载中...