Advertisement
mfgnik

Untitled

Jul 23rd, 2020
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. bool IsSpaciousEnough(int width, int height, int diplomas_amount, int64_t side) {
  5.     return diplomas_amount <= (side / width) * (side / height);
  6. }
  7.  
  8. int64_t BinarySearch(int width, int height, int diplomas_amount) {
  9.     int64_t left = 0;
  10.     int64_t right = static_cast<int64_t>(std::ceil(std::sqrt(diplomas_amount))) * std::max(width, height);
  11.     while (right - left > 1) {
  12.         auto middle = (left + right) / 2;
  13.         if (IsSpaciousEnough(width, height, diplomas_amount, middle)) {
  14.             right = middle;
  15.         } else {
  16.             left = middle;
  17.         }
  18.     }
  19.     return right;
  20. }
  21.  
  22. int main() {
  23.     int width;
  24.     int height;
  25.     int diplomas_amount;
  26.     std::cin >> width >> height >> diplomas_amount;
  27.     std::cout << BinarySearch(width, height, diplomas_amount);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement