This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const int N = 1000010;
int a[N];
int n;
LL K;
bool check(LL mid) {
LL res = 0;
for (int i = 1; i <= n; i++) res += a[i] / mid;
//如果正好整除,那么太棒了!
//如果有余数,那么余数无效,我们只关心整除的那部分
return res >= k;//如果超过了规定的段数,那么说明尺寸小了,可以再调大一点,就是向右逼近
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
// mid的定义:能够切割得到的小段的***最大长度***
LL l = 0, r = a[n];
while (l < r) {
int mid = l + r + 1 >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
//输出
cout << l << endl;
return 0;