Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<int> L;
- int n, k;
- bool valid(int x)
- {
- int ans = 0;
- for (int i = 0; i < L.size(); i++)
- ans += L[i] / x;
- return ans >= k;
- }
- int bin_search()
- {
- int l = 1, r = 10000001, M;
- while (r - l > 1)
- {
- M = (l + r) >> 1;
- if (valid(M))
- l = M;
- else
- r = M;
- }
- if (!valid(l))
- return 0;
- else
- return l;
- }
- int main()
- {
- cin >> n >> k;
- L.resize(n);
- for (int i = 0; i < n; i++)
- cin >> L[i];
- cout << bin_search();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement