[BOJ] 랜선 자르기
Date:
[BOJ] 랜선 자르기
Problem URL : 랜선 자르기
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll n, k;
ll arr[10001];
ll ans;
int main() {
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
cin >> n >> k;
int maxLength = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (maxLength < arr[i]) {
maxLength = arr[i];
}
}
ll l = 1;
ll r = maxLength;
while (true) {
if (l > r) {
break;
}
ll mid = (l + r) >> 1;
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += arr[i] / mid;
}
if (cnt >= k) {
ans = ans < mid ? mid : ans;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans << endl;
return 0;
}
댓글