#P6044. [POI 2018] Prawnicy
[POI 2018] Prawnicy
Background
This problem is translated from POI XXV - Stage I “Prawnicy”.
Problem Description
The “Bajtazar & Son” law firm has just received an order from a very important client. The case is serious and urgent, and it requires holding a meeting with the firm’s lawyers. Each lawyer has a fixed free time interval during which they can attend the meeting. You should choose lawyers so that the meeting time (i.e., the time when all of them are free) is as long as possible.
Input Format
The first line contains two integers and , separated by a single space, representing the number of lawyers employed by the firm and the number of lawyers required for the meeting.
The next lines: the -th line contains two integers and , separated by a single space, indicating that the -th lawyer is free between time and time .
Output Format
Print an integer in the first line, the maximum possible duration of the meeting. You may assume that it is possible to hold a meeting with at least person.
In the second line, print integers separated by spaces, representing the indices (starting from ) of the lawyers attending the meeting. If there are multiple correct answers, your program may output any one of them.
6 3
3 8
4 12
2 6
1 10
5 9
11 12
4
1 2 4
Hint
Sample Explanation
The maximum possible duration of a meeting with three lawyers is . Lawyers numbered , , and can attend, with the meeting lasting from to . Another equally good solution is to choose lawyers , , and , with the meeting lasting from to .

Additional Samples
See pra/pra*.in and pra/pra*.out:
-
Additional sample : test case, , , and there are two ways to choose the lawyers.
-
Additional sample : test case, , , .
-
Additional sample : test case, , , , .
Constraints and Notes
The test set is divided into the following subtasks. The tests for each subtask consist of one or more separate test cases.
| Subtask # | Additional constraints | Score |
|---|---|---|
| , | ||
| , | ||
If your program prints the correct duration in the first line but the rest of the output is incorrect, you will receive of the score.
Translated by ChatGPT 5