Money with Jack ID:6712
Jack is very kind to beggars and every day Jack donates the minimum coin he has whenever a beggar requests him. At the beginning of the day, the number of one rupee coins X, the number of two rupee coins Y and the number of five rupee coins Z in Jack's hand are passed as the input. The number of beggars B who received the alms is also passed as the input. The program must print the money left in Jack's hand at the end of the day as the output.
Boundary Condition(s):
0 <= X, Y, Z <= 1000
0 <= B <= X+Y+Z
Input Format:
The first line contains the value of X, Y and Z separated by space(s).
The second line contains the value of B.
Output Format:
The first line contains the value of the money left in Jack's hand at the end of the day.
Example Input/Output 1:
Input:
2 2 4
5
Output:
15
Explanation:
The first beggar gets a 1 rupee coin.
The second beggar gets a 1 rupee coin.
The third beggar gets a 2 rupee coin.
The fourth beggar gets a 2 rupee coin.
The fifth beggar gets a 5 rupee coin.
Only 3 five rupee coins left in Jack's hand.
Hence the output is 15.
Example Input/Output 2:
Input:
5 2 10
17
Output:
0
PROGRAM IN C:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,d,e=0;
scanf("%d %d %d %d",&a,&b,&c,&d);
int k=abs(d-(a+b+c));
if(k<=c)
e+=k*5;
else if(k<=(c+b))
{e+=(c*5);
e+=((k-c)*2);
}
else if(k<=(c+b+a))
{
e+=(c*5);
e+=(b*2);
e+=((k-(b+c))*1);
}
printf("%d",e);
}
Comments
Post a Comment