题解(适合c++初学者)
2024-05-24 20:17:06
发布于:上海
27阅读
0回复
0点赞
保过
#include <iostream>
using namespace std;
int n,k,a[100005];
bool check(int x){
long long cnt = 0;
for(int i = 0;i < n;i++){
cnt += a[i] / x;
}
if(cnt >= k) return true;
return false;
}
int main(){
cin >> n >> k;
for(int i = 0;i < n;i++){
cin >> a[i];
}
int left = 1,right = 1e9;
while(left + 1 < right){
int middle = (left + right) / 2;
if(check(middle)) left = middle;
else right = middle;
}
if(check(right)) cout << right;
else if(check(left)) cout << left;
else cout << 0;
return 0;
}
这里空空如也
有帮助,赞一个