-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10Problem2.cpp
82 lines (60 loc) · 1.97 KB
/
day10Problem2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Day 10 - Problem 2
Chocolate Frenzy
Walmart has launched a new promotional scheme for chocolates; wherein after giving back a specified amount of chocolate wrappers, you can get a chocolate back. Each chocolate bought comes with a wrapper.
You have some money 'N' initially with you. Provided that you know the cost 'C' of each chocolate, and the number of wrappers 'M' that you can return to get a chocolate back, determine the maximum amount of chocolates that you can eat.
Input Format :
t: Number of test cases
N: Initial Amount of Money
C: Cost of each Chocolate
M: Wrappers to be returned to get back one free chocolate
Output Format :
Single integer describing the maximum number of chocolates you can eat.
Constraints :
1 <= t <= 10^3
2 <= N <= 10^5
1 <= C <= N
2 <= M <= N
Sample Testcase 1 :
t = 1
N = 10
C = 2
M = 5
You can first spend 10 to get 5 chocolates, at 2 per chocolate. After eating, you can then return all the 5 wrappers to get back one free chocolate. Therefore the maximum number of choclates you can eat is 6.
Output : 6
Sample Testcase 2 :
t = 1
N = 12
C = 4
M = 4
You can first spend 12 to get 3 chocolates, at 4 per chocolate. After eating, you will be left with 3 wrappers only. As 3 wrappers are not sufficient to return, you can eat a maximum of 3 chocolates only.
Output : 3
*/
#include <iostream>
using namespace std;
int main(){
int t;
int n;
int c;
int m;
cin >>t;
while(t--){
cin >>n;
cin >>c;
cin >>m;
int sum = 0;
int choco = n/c;
sum += choco;
while(true){
if(choco/m > 0) {
sum += choco/m;
m = choco%m + choco; // wrappers
choco = choco/m;
}
else{
break;
}
}
cout <<sum;
}
}