Ants

Time limit1sMemory limit128 MB

Summary
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 ll cm long. Every ant always moves at a constant speed of 1 cm/s1\,\text{cm/s}. 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 ll and the number of ants nn, separated by a space. Each of the next nn 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 1,000,0001{,}000{,}000.

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

  • 1≤n≤100,0001 \le n \le 100{,}000
  • 1≤l≤1,000,0001 \le l \le 1{,}000{,}000
  • Each ant's position is an integer.
  • 0≤0 \le (ant position) ≤l\le l

Examples1

  1. Example 1

    Input
    2
    10 3
    2
    6
    7
    214 7
    11
    12
    7
    13
    176
    23
    191
    
    Expected output
    4 8
    38 207