cswork / OAOpen practice workspace

SuperhumanOA #3

Optimal Transfer

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesGreedy

Capacities are in ascending order and distinct. A direct connection between any two servers costs the difference of their capacities, and connecting to the nearest server costs 1. Answer 0-based queries.

See "Input" for the standard input/output conventions and constraints added by this site.

Input

n,q≤200000, capacity≤10^9, and each server's nearest server is unique.

Output

Output the minimum connection cost for each query in order.

Example 1

Input:

3 3
2 7 10
0 1 2
2 2 1

Output:

2 1 1

Example 2

Input:

4 3
1 4 9 15
0 3 1
3 0 3

Output:

12 3 11

Example 3

Input:

3 2
5 6 20
2 0
0 1

Output:

2 1

Editorial

Loading solution…