CF612D.The Union of k-Segments

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn segments on the coordinate axis Ox and the number kk . The point is satisfied if it belongs to at least kk 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.

输入格式

The first line contains two integers nn and kk ( 1<=k<=n<=1061<=k<=n<=10^{6} ) — the number of segments and the value of kk .

The next nn lines contain two integers li,ril_{i},r_{i} ( 109<=li<=ri<=109-10^{9}<=l_{i}<=r_{i}<=10^{9} ) each — the endpoints of the ii -th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.

输出格式

First line contains integer mm — the smallest number of segments.

Next mm lines contain two integers aj,bja_{j},b_{j} ( aj<=bja_{j}<=b_{j} ) — the ends of jj -th segment in the answer. The segments should be listed in the order from left to right.

输入输出样例

  • 输入#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
    
首页