Train or Walk Problem

Chefland has all the cities on a straight line. There are N cities in Chefland numbered 1 to N

 

 City i is located at coordinate xi on the x-axis

Guru wants to travel from city A to city B

 He starts at time t=0.

He can walk 1 meter in P secs.

There is a train that travels from city C to city D which travels 1 metre in Q secs which starts at time t=Y secs. Guru can take the train only at city C and leave the train only at city D.

Guru find the minimum time he will need to travel from city A to B

Note that you cannot board the train after time t =Y

Input:

  • First line will contain T, number of testcases. Then the testcases follow.
  • First line of each testcase contains eight space separated integers N,A,B,C,D,P,Q,Y
  • Second line of each testcase contains N space-separated integers with the ii-th integer representing xixi.

Train or Walk

By Sagar Mal Shankhala