Given each friend's starting position and running speed, decide whether all N friends can meet at one point within time T.
Medium5Binary searchSortingMathGreedyInterviewNo attempts yetTime limit2sMemory limit512 MBJunoh Lim, a mischievous hacker who lives in Dongtan, is waiting for lunchtime again. Every day Junoh and his friends gather at one point in the hallway and go to lunch together. The hallway at Sunrin is a straight line, and Junoh and his friends are waiting for the bell in classrooms located along this hallway.
'Ding~ ding-ding~ ding-ding-ding-ding~'
The bell rings! Junoh and his friends must meet at a single point as fast as possible. Otherwise the flood of students pouring out may sweep each of them separately down to the cafeteria.
You are given the classroom position xi of each friend (Junoh included), each student's running speed vi, and the time T left until the flood arrives. Can Junoh and his friends go to lunch together?
The classrooms lie on a one-dimensional line. Each student runs at a constant speed, and all students start running the moment the bell rings. If the friends meet at exactly the moment the flood hits, they count as having met before being swept away.
The first line contains N, the number of friends including Junoh, and T, the time in seconds left until the flood. (1≤N≤50,000, 1≤T≤1,000,000,000) T is a real number with at most four digits after the decimal point. The fractional part may be shorter or absent (for example 2.5 or 1).
The second line contains the positions x1,x2,…,xN of the N students, as natural numbers in meters. (1≤xi≤1,000,000,000)
The third line contains the speeds v1,v2,…,vN of the N students, as natural numbers in meters per second. (1≤vi≤1,000,000,000)
Print 1 if Junoh and all his friends can meet, and 0 otherwise.