-
-
Save jesyspa/9604833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <limits> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
int main() { | |
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | |
for (std::string line; std::getline(std::cin, line);) { | |
std::istringstream iss(line); | |
int money, price_per_chocolate, num_wrappers_per_free_piece; | |
iss >> money >> price_per_chocolate >> num_wrappers_per_free_piece; | |
if (!iss) | |
continue; | |
// Just copy the constraints literally. | |
if (money < 2 || money > 100'000) | |
continue; | |
if (price_per_chocolate < 1 || money < price_per_chocolate) | |
continue; | |
if (num_wrappers_per_free_piece < 2 || num_wrappers_per_free_piece > money) | |
continue; | |
int num_chocolates = 0; | |
while (money >= price_per_chocolate) { | |
money -= price_per_chocolate; | |
num_chocolates++; | |
if (num_chocolates % num_wrappers_per_free_piece == 0) { | |
num_chocolates++; | |
} | |
} | |
std::cout << num_chocolates << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment