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. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  2. JAVA之Lamdba表达式使用摘要

    1. of (of方法其生成的Stream是有限长度的,Stream的长度为其内的元素个数)    Stream<Integer> integerStream = Stream.of(1, ...

  3. 将iPhone5s中的相片批量下载到电脑中

    前言:目前我还在使用iPhone5s这款手机,不过由于自己的无知,在使用手机的过程中发现有些用户的体验不是很好,特别是将手机中的相片批量下载到电脑中这件小事,和Android系统相关的手机相比更不好玩 ...

  4. PureFTP被动端口设置

    修改Pureftp的配置文件把 # PassivePortRange          30000 50000 把前面的#删除 重启pureftpd 注意把被动端口防火墙例外 如果是阿里云主机 安全规 ...

  5. [svc]mysql备份恢复及常用命令

    如何实现mysql读写分离 1.通过程序实现读写分类(性能 效率最佳) php和java都可以通过设置多个连接文件轻松实现对db的读写分离,即当select时,就去连读库的连接文件,当update,i ...

  6. C++11模版元编程的应用

    1.概述 关于C++11模板元的基本用法和常用技巧,我在程序员2015年2月B<C++11模版元编程>一文(后称前文)中已经做了详细地介绍,那么C++11模版元编程用来解决什么实际问题呢, ...

  7. Forward+ Shading架构

    Forward+ = Tile based Light Culling + Tile based Forward Rendering 整体渲染架构分为如下3大步骤: 1.PrePass将场景的min ...

  8. TCP拥塞控制-慢启动、拥塞避免、快重传、快启动

    一般原理:发生拥塞控制的原因:资源(带宽.交换节点的缓存.处理机)的需求>可用资源. 作用:拥塞控制就是为了防止过多的数据注入到网络中,这样可以使网络中的路由器或者链路不至于过载.拥塞控制要做的 ...

  9. 小技巧 - CSS中:hover调试

    在调试CSS的时候,我一般使用Chrome的F12开发者工具,或者FireFox的FireBug直接在元素上面修改好Style后,再写入到CSS中.前几天遇到一个问题就是a:hover,鼠标一移开效果 ...

  10. 关闭2010中 word每次都提示:所做更改会影响共用模板 Normal.dotm

    '您正试图运行的函数包含有宏或需要宏语言支持的内容.而在安装此软件时, 您(或您的管理员)选择了不安装宏或宏的控件的支持功能.' 每次关闭word都要出现这个该死的提示,头痛了半天. 谢谢各位! 我终 ...