To understand problem I checked with others correct solution. I had following input given

1

4 1 3 2 4 3 2 4

1 2 4 5

Output was 9

Can somebody explain the logic behind the above output ?

He directly walks from city 1 (placed at x = 1) to city 3 (placed at x = 4). He has to travel 3 metres in this process, and he takes P = 3 seconds to cover one metre. Hence the answer 9.

ok.

So basically in line 4 1 3 2 4 3 2 4, 1 and 3 means index numbers 1 and 3 (respective number 1 and 4) for last line

Is my interpretation correct ?

Yup.

Thanks

On this site it is difficult and sometimes confusing to understand the problem and scenarios.