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!
n people queue up everyday to purchase Wanmin Restaurant's Boiled
Fish. The i-th person in line wants to buy ai servings of the dish.
The chef prepares q batches of the dish - the j-th batch has kj 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 n-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 n 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 n-th person has
been served, all n people queue up again, so your output in this case
should be n and not 0.
Input
The first line contains two integers n and q(1n,q200000)- the
number of customers and the number of batches prepared by the chef.
The second line contains n integers a1,a2,a3,...,an(1ai109)
the number of servings required by each customer.
The third line contains q integers k1,k2,k3,...,kq(1ki1014)-
ki is the number of servings prepared in the i-th batch.
Output
Print q lines, the i-th of which is the number of customers remaining after the i-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 5 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 1 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)
Write Java Code for the above problem. ( should

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!