Question: Write Java Code for the above problem. ( should not have plagerism ) A . Wanmin Restaurant's Boiled Fish The Wanmin Restaurant is open for
Write Java Code for the above problem. should not have plagerism
A Wanmin Restaurant's Boiled Fish
The Wanmin Restaurant is open for business!
people queue up everyday to purchase Wanmin Restaurant's Boiled
Fish. The th person in line wants to buy servings of the dish.
The chef prepares batches of the dish the th batch has servings
of Boiled Fish. Once a batch is ready, it is given one by one to the person
standing at the front of the queue. The instant a person receives as many
servings as they wanted, they immediately leave the queue and so the
next serving is given to the next person in line till they leave, and so on
After the th person has been served, any remaining servings from
that batch are thrown out and the restaurant is cleaned.
However, the Wanmin Restaurant is quite popular when the restaurant is
being cleaned, the same people line up once again in the exact same
order, and with exactly the same requirements as before. This process
continues as long as the chef continues to make batches.
Your task is to tell the chef how many people remain in the queue after
each batch of Boiled Fish is served. Note that once the th person has
been served, all people queue up again, so your output in this case
should be and not
Input
The first line contains two integers and the
number of customers and the number of batches prepared by the chef.
The second line contains integers
the number of servings required by each customer.
The third line contains integers
is the number of servings prepared in the th batch.
Output
Print lines, the th of which is the number of customers remaining after the th batch has been served.
Sample input output image attached.
In the first sample test:
The first batch serves the first two people completely, so they leave
the queue
The second batch serves all remaining people, so they leave the
queue and then all people queue up again. There are extra
servings in this batch, which are thrown out.
The third batch serves only the first person, who leaves the queue
The fourth batch goes to the second person, but they still want more
serving so nobody leaves the queue
The fifth batch serves the second person, who then leaves the queue
Write Java Code for the above problem. should not have plagerism
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
