Question: c code program: Ferries used to carry cars across the river. In your village, there is still a ferry that can take up to N
c code program: Ferries used to carry cars across the river. In your village, there is still a ferry that can take up to N cars and needs
T minutes to cross the river. A car may arrive at either river bank and wait to be carried to the opposite bank.
The ferry operates continuously between the banks as long it is carrying at least one car or there is at least one
car waiting on either side. Whenever the ferry arrives at one bank, it unloads cars carried and loads up to N cars
waiting at that bank. When there are more than N cars waiting, they are loaded on the firstcomefirstserve basis.
If there is no car waiting on either bank, the ferry stops and waits until one car arrives. The ferry is initially on the
left bank. You are asked to determine at what time each car arrives at the other bank.
Input The first line of input contains three integers N T and M N T M Each of the following
M lines gives the arrival time of a car and the bank at which the car arrives left or right The cars are ordered
by their arrival times so the arrival times are nondecreasing and the time spent on loading and unloading can be
ignored.
Output For each car, you should print one line containing one number, the time at which the car is unloaded at the
opposite bank.
Example
Input:
left
left
left
left
left
left
left
left
left
left
Output:
Example
Input:
right
left
left
Output:
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
