Sunteți pe pagina 1din 2

Analysis and Design of Algorithms : Lab

Assignment-6

March 1, 2017

Problem Statement : A
You are in love with the food being served at our institute’s mess and you make
it a point not to miss it. But there are many more mess food lovers like you,
which means the queues for the food aren’t short. Everyday you spend a good
amount of time standing in the queue. Now you, being the geek that you are,
have decided to come up with an algorithm to minimize this time.

You have observed that the mess has an arrangement for two queues. Each
of the queues has the same n dishes in the same order. The average time spent
in the queue i for any dish j, is ai,j .
You may choose to enter in any of the two queues. The respective waiting time
in the two queues before you can pick up your plate and reach the first dish
is e1 and e2 . Also, once you have taken the dish j from a queue, say queue
1, you can continue in the same queue and wait for dish j + 1 (waiting time
a1,j+1 ), or you may decide to move to the other queue, queue 2 in this case, and
wait for a2,j+1 time for taking the dish j + 1. Continuing in the same queue
costs you no extra waiting time, but transferring from the queue i after taking
the dish j −1, to the dish j on the other queue takes additional waiting time ti,j .

Note :
• You may enter and exit from different queues.
• Once you enter a queue, it is mandatory to put the first dish (dish 1),
from that queue only

• It is necessary to put the dishes in order, i.e. you will start with dish 1,
then put dish 2, and so on till dish n.
• The dishes and the queues are one indexed.

Input
The first line contains an integer n, the number of dishes being served. The
next line has two integers e1 and e2 . The next two line have n integers each,
representing the waiting time for the dishes in queue 1 and queue 2 respectively.

1
Next you get a 2 ∗ n matrix. That is the next 2 lines have n integers each. The
integer ti,j of the matrix represents the transition costs or transition time as
described above.

Note: t1,1 and t2,1 are not defined. In the input they will always be equal
to zero.

Constraints
2 ≤ n ≤ 100000
1 ≤ e1 , e2 ≤ 10000
1 ≤ ai,j ≤ 10000
1 ≤ ti,j ≤ 10000

Output
Print the minimum time required.

Sample Input
4
10 12
4532
2 10 1 4
0745
0928

Sample Output
24

Time Limit
1 sec

S-ar putea să vă placă și