CF612D.The Union of k-Segments
普及+/提高
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.
给你数轴 Ox 上的 n 条线段以及一个整数 k。若某点至少属于 k 条线段,则称该点为满足条件的点。请找出数轴 Ox 上的最小(线段数量最少)线段集合,使得该集合恰好包含所有满足条件的点,且不包含任何其他点。
输入格式
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 106) — the number of segments and the value of k.
The next n lines contain two integers l__i, r__i ( - 109 ≤ l__i ≤ r__i ≤ 109) each — the endpoints of the i-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.
第一行包含两个整数 n 和 k(1≤k≤n≤106)—— 分别表示线段的数量和参数 k 的值。
接下来的 n 行,每行包含两个整数 li、ri(−109≤li≤ri≤109)—— 表示第 i 条线段的两个端点。这些线段可以退化(即长度为零),且彼此之间可以相交。线段以任意顺序给出。
输出格式
First line contains integer m — the smallest number of segments.
Next m lines contain two integers a__j, b__j (a__j ≤ b__j) — the ends of j-th segment in the answer. The segments should be listed in the order from left to right.
第一行包含整数 m —— 所需线段的最少数量。
接下来的 m 行每行包含两个整数 aj、bj(满足 aj≤bj)—— 表示答案中第 j 条线段的左右端点。这些线段应按从左到右的顺序列出。
输入输出样例
输入#1
3 2 0 5 -3 2 3 8
输出#1
2 0 2 3 5
输入#2
3 2 0 5 -3 3 3 8
输出#2
1 0 5
输入解题思路,AI测评打分。不知道怎么写?