#P14090. [ICPC 2023 Seoul R] Lucky Draws

[ICPC 2023 Seoul R] Lucky Draws

题目描述

The ICPC committee is planning a surprise event to cheer on the participating teams. The committee provides each team with a pair of two numbers, AA and BB (ABA\le B), before the competition, which will be used for the lucky draws after the competition. The committee wants to hold KK draws. In each draw, a single number CC is chosen by the committee, and all teams with a pair (A,B)(A,B) such that ACBA\le C\le B win in this draw. To make more teams happy, the committee wants to choose the KK numbers used in the KK draws in advance so that the most teams win. A team can win multiple times but is considered to have won once.

For example, five teams are participating in ICPC and their pairs are (1,2),(1,4),(3,6),(4,7),(5,6)(1, 2), (1, 4), (3, 6), (4, 7), (5, 6), and K=2K=2. When the committee chooses two numbers 22 and 44, four teams with (1,2),(1,4),(3,6)(1, 2), (1, 4), (3, 6) and (4,7)(4, 7) win. The team with (1,4)(1, 4) wins twice because the pair contains both chosen numbers. In fact, all five teams can win if 22 and 55 are chosen. The maximum number of winning teams is five.

Given nn pairs of two integers for teams and the number of lucky draws KK, write a program to output the maximum number of winning teams.

输入格式

Your program is to read from standard input. The input starts with a line containing two integers, nn and KK($1 \le n\le 10,000, 1 \le K\le n, 1 \le n\times K\le 500,000$), where nn is the number of teams and KK is the number of lucky draws. Each of the following nn lines contains two integers AA and BB that represent the pair of a team, where 106AB106-10^6\le A\le B\le 10^6.

输出格式

Your program is to write to standard output. Print exactly one line. The line should contain the maximum number of winning teams. Teams that win more than once should only be counted once.

5 2
1 2
1 4
3 6
4 7
5 6
5
3 2
2 4
1 3
3 5
3
4 1
2 3
1 1
4 5
4 5
2
7 2
5 6
7 9
7 7
1 4
2 3
4 7
4 7
6