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 first-come-first-serve 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 (1<= N, T, M <=10,000). 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 non-decreasing) 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 1
Input:
21010
0 left
10 left
20 left
30 left
40 left
50 left
60 left
70 left
80 left
90 left
Output:
10
30
30
50
50
70
70
90
90
110
Example 2
Input:
2103
10 right
25 left
40 left
Output:
30
40
60

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!