-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1654.cpp
More file actions
53 lines (48 loc) · 786 Bytes
/
1654.cpp
File metadata and controls
53 lines (48 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 1654. 랜선 자르기
// 2020.01.10
// 이분 탐색
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int k, n;
int main()
{
cin >> k >> n;
vector<long long> wire(k);
long long ans = 0;
long long low = 1;
long long high = 0;
for (int i = 0; i < k; i++)
{
cin >> wire[i];
high = max(high, wire[i]);
}
// 이분 탐색
while (low <= high)
{
long long mid = (low + high) / 2;
// 개수 확인
long long total = 0;
for (int i = 0; i < k; i++)
{
total += wire[i] / mid;
}
// 개수 만족
if (total >= n)
{
// 개수 만족한 상태인데 길이도 더 길때 답으로 저장
if (ans < mid)
{
ans = mid;
}
low = mid + 1;
}
else
{
high = mid - 1;
}
}
cout << ans << "\n";
return 0;
}