Files
python/TangDou/LuoGuBook/P2440.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

32 lines
860 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}