All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket.

The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with ids ranging from li to ri, inclusive. Today Fedor wants to take exactly k coupons with him.

Fedor wants to choose the k coupons in such a way that the number of such products x that all coupons can be used with this product x is as large as possible (for better understanding, see examples). Fedor wants to save his time as well, so he asks you to choose coupons for him. Help Fedor!

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·105) — the number of coupons Fedor has, and the number of coupons he wants to choose.

Each of the next n lines contains two integers li and ri ( - 109 ≤ li ≤ ri ≤ 109) — the description of the i-th coupon. The coupons can be equal.

Output

In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted.

In the second line print k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the ids of the coupons which Fedor should choose.

If there are multiple answers, print any of them.

Example

Input
4 2
1 100
40 70
120 130
125 180
Output
31
1 2
Input
3 2
1 12
15 20
25 30
Output
0
1 2
Input
5 2
1 10
5 15
14 50
30 70
99 100
Output
21
3 4

Note

In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total.

In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example.

题意:取n个区间中的k个,使得其交集最大

题解:排序左边界,枚举之,再创建一个k大小的右边界队列,维护其队首为最大能取的右边界。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
struct node{
int a,b;
int s; friend bool operator < (node x,node y){
return x.b > y.b;
}
}k[maxn];
bool cmp(node x,node y){
return x.a < y.a;
} int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%d%d",&k[i].a,&k[i].b);
k[i].s=i+;
} priority_queue<node> q;
sort(k,k+n,cmp); int ans = ; int l = ;
for(int i=;i<n;i++){ q.push(k[i]);
if(q.size()>m)
q.pop();
int left = k[i].a;
int right = q.top().b; if(right - left + > ans && q.size() == m){
l = left;
ans = right - left + ;
}
} cout<<ans<<endl;
if(ans!=)
for(int i=;i<n && m;i++){
if(l>=k[i].a && ans+l-<=k[i].b){
cout<<k[i].s<<" ";
m--;
}
}
else
for(int i=;i<m;i++)
cout<<i+<<" "; return ;
}

CodeForces - 754D的更多相关文章

  1. 【codeforces 754D】Fedor and coupons

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. codeforces 754D. Fedor and coupons

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  3. CodeForces 754D Fedor and coupons (优先队列)

    题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, ...

  4. CodeForces 754D Fedor and coupons&&CodeForces 822C Hacker, pack your bags!

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  5. CodeForces 754D Fedor and coupons ——(k段线段最大交集)

    还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果 ...

  6. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  9. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

随机推荐

  1. rman输出日志的几种方法(转)

    在使用rman的时候经常会碰到以下两种场景,需要把rman的日志输出到文件中: 1.显示的日志太多,导致一个屏幕显示不完,影响了问题的诊断,这时候需要把rman的log输出到文本中,整个的诊断过程就相 ...

  2. 如何制作initrd.img文件

    2008-11-12 16:02:37    initrd.img文件是redhat,mandrake等linux发布使用的内存镜像文件.镜像中是一个微型系统.在安装系统时,将initrd.img展开 ...

  3. 如何部署hadoop集群

    假设我们有三台服务器,他们的角色我们做如下划分: 10.96.21.120 master 10.96.21.119 slave1 10.96.21.121 slave2 接下来我们按照这个配置来部署h ...

  4. alter日志报WARNING: too many parse errors

    数据库版本:12.2.0 操作系统版本:RHEL7.2 最近观察到一个数据库alert日志老是报硬解析太多错误,且对应的sql语句都是查看数据字典表: 2017-06-16T08:46:46.4174 ...

  5. 使用DIV弹出框的代码示例,备忘。

    1.思路 使用DIV模拟弹出框,一共用三个div: divWindow: 原来的界面内容区域 divLogin:要弹出的内容区域 divBackground:给弹出内容区域做个遮罩的区域. 点击 “请 ...

  6. Current online Redo 和 Undo 损坏的处理方法

    转自:http://blog.csdn.net/tianlesoftware/article/details/6261475 Oracle 不同故障的恢复方案 http://blog.csdn.net ...

  7. idea git 使用

    第一部  测试  本地git 是否已经成功安装 centos 7 发行版默认已经安装 第二部: 测试 github 连接是否成功,需要输入用户密码 第三部:创建git项目管理两种方式 1. 菜单 VC ...

  8. Java 分布式和集中式理解

    文章转载自:https://blog.csdn.net/youanyyou/article/details/79406507

  9. [转]对form:input标签中的数字进行格式化

    原文地址:https://blog.csdn.net/qq_29662201/article/details/80708373 数字进行格式化(保留2位小数) 单独使用<fmt:formatNu ...

  10. 【iCore1S 双核心板_ARM】例程十五:USB_HID实验——双向数据传输

    实验方法: 1.USB_HID协议免驱动,此例程不需要驱. 2.将跳线冒跳至USB_OTG,通过Micro USB 线将iCore1S USB-OTG接口与电脑相连. 3.打开上位机软件usb_hid ...