Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Traffic Lights

#1163
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

There is a street of length xx whose positions are numbered 0,1,…,x0,1,\ldots,x. Initially there are no traffic lights, but nn sets of traffic lights are added to the street one after another.

Your task is to calculate the length of the longest passage without traffic lights after each addition.

Input

The first input line contains two integers xx and nn: the length of the street and the number of sets of traffic lights.

Then, the next line contains nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n: the position of each set of traffic lights. Each position is distinct.

Output

Print the length of the longest passage without traffic lights after each addition.

Constraints
  • 1≤x≤1091 \le x \le 10^9
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 0<pi<x0 < p_i < x
Sample Test Cases (1)
Example 1ID: sample-1
Input
8 3
3 6 2
Expected Output
5 3 3
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
8 3
3 6 2
Expected Output
5 3 3