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.

Examples
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 31products 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.

题意:在所有的区间里选取重复次数为k的子区间,且长度要最大

比如40-70在第一个区间是子区间,第二个区间也是,且长度最大

解法:

1 优先队列维护右端点最小值

2 额、、区间左端点从小到大排序

3 每次装了k个区间后,用队列顶端点减去当前区间的左端点就是结果了

4 然后求有多少区间符合就好了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node{
int x,y;
int id;
}node[*];
bool Sort(Node a,Node b){
return a.x<b.x;
}
priority_queue<int,vector<int>,greater<int>>Qr;
vector<int>Ve;
int main()
{
int temp;
int ans=;
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d%d",&node[i].x,&node[i].y);
node[i].id=i;
}
sort(node+,node+n+,Sort);
for(int i=;i<=n;i++){
int l=node[i].x;
Qr.push(node[i].y);
while(Qr.size()>k){
Qr.pop();
}
if(Qr.size()==k){
// cout<<Qr.top()<<"A"<<endl;
if(Qr.top()-l+>ans){
ans=Qr.top()-l+;temp=i;
// cout<<ans<<endl;
}
}
}
printf("%d\n",ans);
if(ans==){
for(int i=;i<=k;i++){
printf("%d ",i);
}
}else{
for(int i=;i<=temp;i++){
if(node[i].y-node[temp].x+>=ans){
cout<<node[i].id<<" ";
}
}
}
return ;
}

Codeforces Round #390 (Div. 2) D的更多相关文章

  1. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  2. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)

    http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...

  3. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

  4. Codeforces Round #390 (Div. 2)

    时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...

  5. Codeforces Round #390 (Div. 2) E(bitset优化)

    题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...

  6. Codeforces Round #390 (Div. 2) A B C D

    这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...

  7. Codeforces Round #390 (Div. 2) B

    Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. ...

  8. Codeforces Round #390 (Div. 2) A

    One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into sev ...

  9. Codeforces Round #390 (Div. 2) A+B+D!

    A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...

随机推荐

  1. Jenkins安装部署及tomcat的入门介绍

    这里我们使用的方法是用servlet容器来部署jenkins,使用的是tomcat 下载下来tomcat,解压 bin目录下存放的一些启动关闭批处理文件 conf目录下放的一些配置文件,配置虚拟主机之 ...

  2. js程序开发-2

    <h1>DOM节点操作</h1> createElement() 创建节点:返回一个元素对象; cloneNode() 克隆节点,接受一个参数deep,值为true或false ...

  3. poj 3617 Best Cow Line 解题报告

    题目链接:http://poj.org/problem?id=3617 题目意思:给出一条长度为n的字符串S,目标是要构造一条字典序尽量小,长度为n的字符串T.构造的规则是,如果S的头部的字母 < ...

  4. 自适应布局all样式

    /*css document*/@charset "utf-8"*{-webkit-tap-highlight-color:rgba(0,0,0,0); padding:0; ma ...

  5. vue 里面输出带标签的html

    使用 v-html 指令 <div v-html="'<P>11111111</P><P>11111111</P>'"> ...

  6. C++之函数适配器--绑定器bind原理图解

    转自:http://www.cnblogs.com/xusd-null/p/3698969.html#3081606 本文解释了bind 是如何工作的.为了清晰,图中的语法作了一些简化(例如,省略函数 ...

  7. 魔法少女-dp

    魔法少女 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %I64d & %I64u 前些时间虚渊玄的巨献小圆着实火 ...

  8. FFmpeg常用命令 (三)流媒体

    前言 如此强大的FFmpeg,能够实现视频采集.视频格式转化.视频截图.视频添加水印.视频切片.视频录制.视频推流.更改音视频参数功能等.通过终端命令如何实现这些功能,Richy在本文做一记录,以备之 ...

  9. Array 对象

    Array的对象用于在单个的变量中存储多个值. constructor 返回对创建此对象的数组函数的引用. demo: let arr=[];  arr.constructor==Array let ...

  10. 什么是weex

    Weex是一个使用web开发体验来开发高性能原生应用的框架 在集成WeexSDK之后,你可以使用javaScript和现代流行的前端框架来开发移动应用. Weex的结构是解耦的,渲染引擎与语法层是分开 ...