套模板秒了
2024-02-13 18:27:07
发布于:湖南
37阅读
0回复
0点赞
#include <iostream>
#include <cstdio>
using namespace std;
int a[100005];
int n, m;
int mx;
bool check(int x){
int ct = 0;
for(int i = 1; i <= n; i++){
ct += a[i] / x;
}return ct >= m;
}
int main(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
mx = max(mx, a[i]);
}int left = 1, right = mx;
while(left <= right){
int mid = (left + right) / 2;
if(check(mid)) left = mid + 1;
else right = mid - 1;
}cout << left - 1;
return 0;
}
这里空空如也
有帮助,赞一个