-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
bool check(vector <int>& v, int n, long long length); | ||
int binary_serach(vector <int>& v, int n); | ||
|
||
int main() { | ||
int k, n; | ||
cin >> k >> n; | ||
vector <int> trees(k); | ||
for (auto& i : trees) { | ||
cin >> i; | ||
} | ||
cout << binary_serach(trees, n); | ||
return 0; | ||
} | ||
|
||
bool check(vector <int>& v, int n, long long length) { | ||
int cnt = 0; | ||
for (const auto& i : v) { | ||
cnt += i / length; | ||
} | ||
return cnt >= n; | ||
} | ||
|
||
int binary_serach(vector <int>& v, int n) { | ||
long long lo = 1, hi = 2147483648; //자를 수 있는 랜선의 범위 | ||
while (lo + 1 < hi) { | ||
long long mid = (lo + hi) / 2; | ||
if (check(v, n, mid)) lo = mid; | ||
else hi = mid; | ||
} | ||
return lo; | ||
} |