NEW ATM DESIGN | CODE VITA 2019


Problem Description

Automated Teller Machine (ATM) is an electronic device that enables people to withdraw cash from their bank account. Every ATM has a limit for number of currency notes (say N), it can give at a time.

A bank wants to design an ATM for school students. The unique feature of this ATM would be that it would always give maximum number of currency notes possible, to make the students happy.  Available denomination of currency notes in the ATM are 100, 200, 500, 1000


Constraints

N<100

Input Format


First Line provides an integer, N

Second Line provides an integer denoting the amount you want to withdraw (in multiples of 100)

Third Line provides an integer denoting the available currency note of Rs 100 in the ATM

Fourth Line provides an integer denoting the available currency note of Rs 200 in the ATM

Fifth Line provides an integer denoting the available currency note of Rs 500 in the ATM

Sixth Line provides an integer denoting the available currency note of Rs 1000 in the ATM

Output


One line containing the maximum number of currency note possible for the desired withdrawal amount. Output should be 0 (zero) if transaction is not possible, for example if sufficient fund is not available in the ATM.

Example 1

Input

10

1300

10

10 

10

10


Output

10


Explanation

Here,

7 * 100 + 3* 200 + 0*500 +0*1000 hence maximum possible currency = 10. 


Example 2

Input

5

1700

1

2

2

2


Output

3


Explanation

Here,

0 * 100  + 1 * 200 + 1 * 500 +1 * 1000 hence maximum possible currency = 3.



6 comments:

  1. Well, I'm looking for a solution to this problem.
    Any help would be grateful.

    ReplyDelete
    Replies
    1. Anonymous23:28

      #include
      #include
      int main()
      {
      int N, amt,i,j,k,l,a[4],_100,_200,_500,_1000;
      scanf("%d",&N);
      scanf("%d",&amt);
      scanf("%d",&_100);
      scanf("%d",&_200);
      scanf("%d",&_500);
      scanf("%d",&_1000);
      for(i=0;i<=_1000;i++)
      {
      for(j=0;j<=_500;j++)
      {
      for(k=0;k<=_200;k++)
      {
      for(l=0;l<=_100;l++)
      {
      if((i*1000+j*500+k*200+l*100==amt) && (i+j+k+l<=N))
      {
      int res=i+j+k+l;
      printf("%d",res);
      exit(0);
      }
      }
      }
      }
      }
      return 0;
      }

      Delete
    2. Bro why did you take a[4]

      Delete
  2. Anonymous23:31

    I tried this code, it passed the public test cases, but didn't clear the private test cases. I'm not getting where this code is going wrong. If anyone finds the mistake in it, reply for the comment.

    ReplyDelete
    Replies
    1. Anonymous03:01

      #include
      #include
      int main()
      {
      int N, amt,i,j,k,l,a[4],_100,_200,_500,_1000,max=0;
      scanf("%d",&N);
      scanf("%d",&amt);
      scanf("%d",&_100);
      scanf("%d",&_200);
      scanf("%d",&_500);
      scanf("%d",&_1000);
      for(i=0;i<=_1000;i++)
      {
      for(j=0;j<=_500;j++)
      {
      for(k=0;k<=_200;k++)
      {
      for(l=0;l<=_100;l++)
      {
      if((i*1000+j*500+k*200+l*100==amt) && (i+j+k+l<=N))
      {
      int res=i+j+k+l;
      if(max<res)
      {
      max=res;
      }
      //printf("%d",res);
      }
      }

      }
      }
      }
      if(max<=0)
      {
      printf("0");
      exit(0);
      }
      else
      {
      printf("%d",max);
      exit(0);
      }
      return 0;
      }

      Delete
  3. I were using dp but I got tle
    but bruteforce got AC
    just applied for loops
    import java.util.*;

    public class Main
    {
    public static void main(String[] args) {
    Scanner kb=new Scanner(System.in);
    int n=kb.nextInt();
    int max=Integer.MIN_VALUE;

    int amount=kb.nextInt(),a=kb.nextInt(),b=kb.nextInt(),c=kb.nextInt(),d=kb.nextInt();
    for(int i=0;i<=a;i++)
    for(int j=0;j<=b;j++)
    for(int k=0;k<=c;k++)
    for(int l=0;l<=d;l++)
    {
    if((i*100)+(j*200)+(k*500)+(l*1000)==amount && (i+j+k+l)<=n)
    {
    max=Math.max(max,i+j+k+l);
    }
    }
    if(max<=0)System.out.println(0);
    else System.out.println(max);
    }
    }









    ReplyDelete

DISTRIBUTE BOOKS | Code vita 2019

Problem Description  For enhancing the book reading, school distributed story books to students as part of the Children’s day celebration...