# Problem Link:

## Setter: Alei Reyes

## Tester: Triveni Mahatha

## Editorialist: Triveni Mahatha

# Difficulty:

EASY MEDIUM

# Prerequisites:

Binary Search, Greedy

# Problem:

N students are standing at distinct points in the X-axis. Every students will start running at t = 0. assign direction (left/right) to each of them such that the first time when any two students cross each other is as large as possible. Speed of every students is given.

# Quick Explanation:

Do binary search on the time. Suppose at any step in the binary search, we are are trying to find whether it is possible to assign direction such that no students will cross before some time say

**t**.

To check, whether it is possible to assign direction. We fix the direction of leftmost students towards left (without loss of generality). For every other student from left to right, we try to fix the direction to left itself if it crosses non of the students before time t. And move to next student.

If it is not possible, we try to fix the direction as right. If it is possible then move to next student.

If we are able to assign direction to each students in that manner then the answer is yes, otherwise it is not possible.

### SOLUTION:

# Time Complexity:

For required precision, iterating 100 steps in the binary search is enough. Let’s say the number of steps be **S**.

O(S N) per test case.

# Space Complexity:

O(N)