C Programming Language
Problem Title : Promotion
Jojo is at the supermarket buying monthly groceries. As he was passing alley by alley, a certain banner caught his interest. Buy K cans of cola and get 1 free while one can of cola costs D dollars. As an avid cola fan, Jojo wouldn’t want to miss this amazing opportunity. Jojo is bad at math and so he asks you to count the price that he needs to pay if he plans to buy N cans of cola.
Format Input
The only line of input contains N , K, and D which denotes the number of cans Jojo is planning to buy, the promotion, and the price of each can consecutively.
Format Output
The output of this problem will only be consisting of the price Jojo needs to pay.
Constraints
Sample Input & Output (1) (standard input & output)
6 3 1
5
Sample Input & Output (2) (standard input & output)
6 3 3
15
Explanation:
In the first & second sample test case, Jojo gets 1 can for free. Thus he only needs to pay for the other 5 cans.
#include<stdio.h>
int main(){
long int n,k,d;
scanf("%ld %ld %ld",&n,&k,&d); //taking
inputs n , k, d respectively
printf("%ld\n",n/(k+1)*k*d+(n%(k+1))*d);// for every
k+1 cans we pay for only k cans so n/(k+1)*k*d
//and left over cans(n % k+1)
which will be less k+1 we them all
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.