Advertisement
dmkozyrev

tle

Apr 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. typedef int64_t Int;
  4.  
  5. int main() {
  6.     Int nCandy, nMan, maxX, maxCountPerMan;
  7.     std::cin >> nCandy >> nMan >> maxX >> maxCountPerMan;
  8.    
  9.     Int answ = 0;
  10.     for (Int countPerMan = 1; countPerMan <= maxCountPerMan; ++countPerMan) {
  11.        
  12.         std::function<Int(Int)> calc = [&](Int x) {
  13.             return x > maxX ? 0 : x * ((nCandy + x * nMan-1) / (x * nMan));
  14.         };
  15.        
  16.         // Какой x выбрать чтобы Аркадий получил на руки ровно countPerMan раз
  17.         // countPerMan * x * k >= nCandy
  18.         Int x = (nCandy + countPerMan * nMan-1) / (countPerMan * nMan);
  19.         //std::cout << "countPerMan = " << countPerMan << ", x = " << x << std::endl;
  20.         answ = std::max(answ, calc(x));
  21.         // Пробуем увеличивать x на 1
  22.         while (true) {
  23.             ++x;
  24.             // Сколько раз получит на руки аркадий?
  25.             Int d = (nCandy - nCandy % x + nMan*x-1) / (nMan * x);
  26.             if (d == countPerMan) {
  27.                 answ = std::max(answ, calc(x));
  28.             } else {
  29.                 break;
  30.             }
  31.         }
  32.     }
  33.     assert(answ != 0);
  34.     std::cout << answ << std::endl;
  35.    
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement