#P7688. [CEOI 2005] Ticket Office

[CEOI 2005] Ticket Office

Description

The ticket office sells concert tickets, but it does not sell tickets for single seats. Instead, it sells group tickets for a fixed number of consecutive seats. The office has received a large number of purchase orders. A purchase order for a group of seats specifies the smallest seat number in that group. The office may not be able to fulfill all purchase orders. Also, if it assigns seats strictly according to the purchase orders, many seats may remain empty. Therefore, the office uses the following allocation and pricing strategy. If a purchase order is accepted and the assigned seats are exactly the requested seats, then the buyer pays full price (22 petaks). If a purchase order is accepted but the assigned seats differ from the requested seats (in at least one position), then the buyer pays half price (11 petak). The goal is to maximize the total revenue.
Please write a program to compute the maximum revenue that can be achieved, and assign seats to the selected orders to achieve this revenue.

Input Format

The first line contains two integers, MM and LL. MM is the number of seats, and LL is the number of consecutive seats in each group. Seat numbers range from 11 to MM. The second line contains an integer NN, the number of purchase orders. The third line contains NN integers defining the purchase orders. The ii-th number zz in this line means that the ii-th buyer requests a group of seats starting from seat zz and ending at seat z+L1z+L-1.

Output Format

The first line contains an integer SS, the maximum revenue. The second line contains an integer QQ, the number of accepted orders. The next QQ lines describe the seat assignments. Each line contains a pair of integers xx yy. The pair xx yy means that buyer xx receives seats starting from seat number yy. These lines must be sorted in increasing order of seat number.

20 3
7
4 2 10 9 16 15 17
9
6
4 1
1 4
2 7
3 10
6 13
5 16

Hint

Constraints

For 100%100\% of the testdata, 1M3×1041 \leq M \leq 3 \times 10^4, 1L1001 \leq L \leq 100, 1N1051 \leq N \leq 10^5, 1zML+11 \leq z \leq M-L+1.

Notes

From Ticket Office, CENTRAL-EUROPEAN OLYMPIAD IN INFORMATICS 2005.
Translated and整理 (zhengli) by

/user/160701

Translated by ChatGPT 5