AmazonOA #224
Get Minimum Time
估计中等可在线判题
Servers 1..total form a ring with unit-length edges. Choose any starting server and visit all target servers along one continuous sequential route; crossing each edge takes 1 unit of time, and this is not a simultaneous broadcast in both directions. Targets are distinct.
输入格式
The first line contains n total; the second line contains n target IDs. 1≤total≤10^9, 1≤n≤min(total,100000), 1≤ID≤total. The original constraint ID≤n conflicts with the statement and all examples, so it is restored to ≤total according to the statement.
输出格式
Output a single integer, the answer.
样例 1
输入:
3 8
2 6 8
输出:
4
样例 2
输入:
2 5
1 5
输出:
1
样例 3
输入:
1 10
4
输出:
0
样例说明
The answers are 4, 1 and 0. With a single target, simply start there.