luogu#P6398. [COI 2008] KOLEKCIJA

[COI 2008] KOLEKCIJA

Problem Description

Igor has a playlist containing nn songs, numbered from 11 to nn. Today he is going to listen to mm songs.

When playing the ii-th song, the information of kk consecutive songs will be shown in a list. These kk consecutive songs must include the ii-th song, and there are no other requirements.

When a song is shown in the list, its information will be read once. If a song is shown in the list multiple times, its information will only be read once (no matter whether the two displays are consecutive).

Please give a plan that makes the number of songs whose information gets read as small as possible.

Input Format

The first line contains two integers, representing the number of songs in the playlist nn and the given parameter kk.

The second line contains one integer, representing the number of songs Igor will listen to, mm.

Lines 33 to (m+2)(m + 2) each contain one integer, representing the index aia_i of the ii-th song Igor will listen to.

Output Format

This problem uses a Special Judge.

In the first line, output an integer tt, the minimum number of times song information is read.

In lines 22 to (m+1)(m + 1), output two integers per line. On line (i+1)(i + 1), output li,ril_i, r_i, meaning that when listening to the ii-th song, the information of songs from lil_i to rir_i is displayed.

Your output must satisfy rili+1=kr_i - l_i + 1 = k, 1li<rin1 \leq l_i \lt r_i \leq n, and the number of songs read according to your plan is tt.

10 3
5
4
5
8
7
6

5 
4 6 
4 6 
6 8 
6 8 
6 8
15 4
6
6
14
11
3
8
5

10
3 6
11 14 
11 14
3 6
5 8
3 6
1000 301
3
300
500
700

401
300 600
350 650
400 700

Hint

Constraints

For all test cases, it is guaranteed that:

  • 1k<n1091 \leq k \lt n \leq 10^9, 1m3×1051 \leq m \leq 3 \times 10^5.
  • 1ain1 \leq a_i \leq n, and all aia_i are pairwise distinct.

Scoring

  • If the number of output numbers is less than (2m+1)(2 \cdot m + 1), or the number tt in the first line is different from the answer, you will get 0%0\% of the score for that test point.
  • If tt is the same as the answer but the output plan is incorrect, you will get 50%50\% of the score for that test point.
  • If tt is the same as the answer and the output plan is correct, you will get 100%100\% of the score for that test point.

Notes

This problem is translated from COCI2007-2008 COI2008 T2 KOLEKCIJA. The translation and SPJ are provided by 一扶苏一.

Translated by ChatGPT 5