Ants
Time limit1sMemory limit128 MB
Given ant positions on a rod of length l, choose each ant's initial direction to minimize and maximize the time for all ants to fall off.
- Level
Easy3 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Several ants are placed on a rod that is cm long. Every ant always moves at a constant speed of . When an ant reaches either end of the rod, it immediately falls off. Whenever two ants meet, both of them instantly reverse direction and keep moving.
You know the initial position of every ant, but you do not know whether each ant initially moves to the left or to the right. Assuming the initial directions can be chosen freely, write a program that finds the shortest possible time and the longest possible time until every ant has fallen off the rod.
Input
The first line contains the number of test cases. For each test case, the first line contains the rod length and the number of ants , separated by a space. Each of the next lines contains the initial position of one ant. A position is an integer distance measured from the left end of the rod. Every number in the input is at most .
Output
For each test case, print two integers. The first is the shortest possible time for all ants to fall off the rod, and the second is the longest possible time. Separate the two numbers with a space.
Constraints
- Each ant's position is an integer.
- (ant position)