#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int sum = 0, n, k, maxx = 0;
cin >> n >> k;
int l[n];
for (int i = 0; i < n; i++)
{
cin >> l[i];
maxx = max(maxx, l[i]); // 找出最大值
}
sort(l, l + n); // 二分必须有序
int left = 1, right = maxx;
while (left <= right)
{
int mid = (right + left) >> 1;
for (int e : l)
{
sum += e / mid;
}
if (sum >= k)
{
left = mid + 1;
}
else if (sum < k)
{
right = mid - 1;
}
else
{
cout << mid;
return 0;
}
sum = 0;
}
cout << left - 1;
getchar();
return 0;
}
【C++】洛谷P2440木材加工
于 2022-12-06 15:31:13 首次发布