B) Race Cars

0

0 votes
Problem

There is a race going on between N cars the finish being at Z, given an array of positions called X, and an array of their speeds S. Can you predict which car will finish at position 1,2 and 3?

X[i] denotes the current position of ith car,
S[i] denotes the speed of the ith car.

Assume that the cars will move with this speed for the remainder of the race, Also finish time is only calculated in integers. (  Rounded down i.e if car is at 0 finish line =3 and speed =2 , time = 3/2 = 1 )

In case of tie car with lower index is preferred.

Input :

N, Z in separated by space, followed by X in a new line ( N spaced integers), followed by S in next line ( N spaced integers )

Constraints :

3<=N<=10^5 , 2<=Z<=10^9

0<=X[i]<Z , 1<=S[i]<=10^3

Output :

3 spaced integers, denoting the index of 1st 2nd and 3rd cars ( in 0 based indexing)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Car 1 , Position = 0 , Speed = 5 , time = 10 / 5 = 2

Car 2 , Position = 1 , Speed = 4 , time = 9 / 4 = 2.25 = 2

Car 3 , Position = 5 , Speed = 3 , time = 5 / 3 = 1.66 = 1

So result is Car 3 finishes 1st , Car 1 finishes 2nd , Car  2 Finishes 3rd

3 1 2

Editor Image

?