We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int n = in.nextInt();
int c = in.nextInt();
int m = in.nextInt();
int s = n/c;
int wrapper = n/c;
while(wrapper-m>=0){
wrapper-=(m-1);
s++;
}
System.out.println(s);
}
}
The trick resides in while you are having a free chocolate, you have another more changeable wrapper. So, while you have wrappers, if you can change it for another choco (wrapper-m>=0), decrease your current wrappers as much as you can deliver for a new choco minus 1. That minus 1 means that you will have another more wrapper coming from your new free choco =)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Chocolate Feast
You are viewing a single comment's thread. Return to all comments →
It works for me:
The trick resides in while you are having a free chocolate, you have another more changeable wrapper. So, while you have wrappers, if you can change it for another choco (wrapper-m>=0), decrease your current wrappers as much as you can deliver for a new choco minus 1. That minus 1 means that you will have another more wrapper coming from your new free choco =)