#P6044. [POI 2018] Prawnicy

    ID: 10091 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>贪心2018POI(波兰)Special Judge

[POI 2018] Prawnicy

Background

This problem is translated from POI XXV - Stage IPrawnicy”.

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 kk lawyers so that the meeting time (i.e., the time when all of them are free) is as long as possible.

Brief statement.

Input Format

The first line contains two integers nn and k (1kn)k\ (1\le k\le n), 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 nn lines: the ii-th line contains two integers aia_i and bi (1ai<bi109)b_i\ (1\le a_i<b_i\le 10^9), separated by a single space, indicating that the ii-th lawyer is free between time aia_i and time bib_i.

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 11 person.

In the second line, print kk integers separated by spaces, representing the indices (starting from 11) 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 44. Lawyers numbered 11, 22, and 44 can attend, with the meeting lasting from 44 to 88. Another equally good solution is to choose lawyers 22, 44, and 55, with the meeting lasting from 55 to 99.

Additional Samples

See pra/pra*.in and pra/pra*.out:

  • Additional sample 11: 11 test case, n=7n=7, k=3k=3, and there are two ways to choose the lawyers.

  • Additional sample 22: 11 test case, n=k=1000n=k=1000, ai=ia_i=i, bi=106+ib_i=10^6+i.

  • Additional sample 33: 11 test case, n=1000n=1000, k=1k=1, ai=2i1a_i=2i-1, bi=2ib_i=2i.

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
11 n20n\le 20 2020
22 n300n\le 300ai,bi300a_i,b_i\le 300 1515
33 n5000n\le 5000
44 n106n\le 10^6k{1,n}k\in \{1,n\}
55 n106n\le 10^6 3535

If your program prints the correct duration in the first line but the rest of the output is incorrect, you will receive 40%40\% of the score.

Translated by ChatGPT 5