Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- int countWires(const std::vector<int>& wires, int len) {
- int count = 0;
- for (int i = 0; i < wires.size(); ++i) {
- count += wires[i] / len;
- }
- return count;
- }
- void search(const std::vector<int>& wires, int count) {
- int left = 0;
- int right = 1e7 + 1;
- int result = 0;
- while (left < right - 1) {
- int mid = (left + right) / 2;
- if (mid == 0) {
- left = mid + 1;
- }
- if (countWires(wires, mid) < count) {
- right = mid;
- } else {
- left = mid;
- result = std::max(result, mid);
- }
- }
- std::cout << result;
- }
- int main() {
- int size, count;
- std::cin >> size >> count;
- std::vector<int> wires(size);
- for (int i = 0; i < size; ++i) {
- std::cin >> wires[i];
- }
- search(wires, count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment