Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- bool IsSpaciousEnough(int width, int height, int diplomas_amount, int64_t side) {
- return diplomas_amount <= (side / width) * (side / height);
- }
- int64_t BinarySearch(int width, int height, int diplomas_amount) {
- int64_t left = 0;
- int64_t right = static_cast<int64_t>(std::ceil(std::sqrt(diplomas_amount))) * std::max(width, height);
- while (right - left > 1) {
- auto middle = (left + right) / 2;
- if (IsSpaciousEnough(width, height, diplomas_amount, middle)) {
- right = middle;
- } else {
- left = middle;
- }
- }
- return right;
- }
- int main() {
- int width;
- int height;
- int diplomas_amount;
- std::cin >> width >> height >> diplomas_amount;
- std::cout << BinarySearch(width, height, diplomas_amount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement