Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* AniG owns S leva and wants to spend as much of them as she can. She also has 3 favorite types of cakes.
- The first one costs C1 leva, the second one C2 leva and the third one C3 leva.
- In the shop there are infinite number of cakes but AniG has only S leva.
- AniG should spend as much as she can of his money to buy some cakes.
- Find the maximum amount of money (no more than S) that she can spend to buy cakes.
- On the first line there will be the number S.
- On the second, third and fourth line there will be the numbers C1, C2 and C3.
- Output the biggest possible amount that AniG can spend. */
- "use strict";
- function solve(args) {
- var s = parseInt(args[0]);
- var c1 = parseInt(args[1]);
- var c2 = parseInt(args[2]);
- var c3 = parseInt(args[3]);
- var amounts = [];
- var i, j, k, amount;
- for (i = 0; i < 100; i += 1) {
- for (j = 0; j < 100; j += 1) {
- for (k = 0; k < 100; k += 1) {
- amount = c1 * i + c2 * j + c3 * k;
- if (amount <= s) {
- amounts.push(amount);
- }
- }
- }
- }
- amounts.sort(function (a, b) {
- return b - a
- });
- console.log(amounts[0]);
- }
- solve(['110', '13', '15', '17']);
- solve(['20', '11', '200', '300']);
- solve(['110', '19', '29', '39']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement