Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef int64_t Int;
- int main() {
- Int nCandy, nMan, maxX, maxCountPerMan;
- std::cin >> nCandy >> nMan >> maxX >> maxCountPerMan;
- Int answ = 0;
- for (Int countPerMan = 1; countPerMan <= maxCountPerMan; ++countPerMan) {
- std::function<Int(Int)> calc = [&](Int x) {
- return x > maxX ? 0 : x * ((nCandy + x * nMan-1) / (x * nMan));
- };
- // Какой x выбрать чтобы Аркадий получил на руки ровно countPerMan раз
- // countPerMan * x * k >= nCandy
- Int x = (nCandy + countPerMan * nMan-1) / (countPerMan * nMan);
- //std::cout << "countPerMan = " << countPerMan << ", x = " << x << std::endl;
- answ = std::max(answ, calc(x));
- // Пробуем увеличивать x на 1
- while (true) {
- ++x;
- // Сколько раз получит на руки аркадий?
- Int d = (nCandy - nCandy % x + nMan*x-1) / (nMan * x);
- if (d == countPerMan) {
- answ = std::max(answ, calc(x));
- } else {
- break;
- }
- }
- }
- assert(answ != 0);
- std::cout << answ << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement