Codeforces Round #390 (Div. 2) D
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!
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.
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.
4 2
1 100
40 70
120 130
125 180
31
1 2
3 2
1 12
15 20
25 30
0
1 2
5 2
1 10
5 15
14 50
30 70
99 100
21
3 4
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的更多相关文章
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- 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 ...
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...
- Codeforces Round #390 (Div. 2)
时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...
- Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果 (超出的部分循环处理) 一种做法是使用fft,比较难写,所以没有写 这里使用一个暴力的做法,考虑到一共只出现26个字符 所以使用一 ...
- Codeforces Round #390 (Div. 2) A B C D
这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...
- 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. ...
- 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 ...
- Codeforces Round #390 (Div. 2) A+B+D!
A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- noip2005篝火晚会
这是一道不算太难的题,但愚蠢的我并没有想到. 首先,判断无解的情况:他想相邻的不想与他相邻. 然后,构造出合法的数列,因为第一位左边有两种选择,且构造出的环不等价,所以要做两次. (这一点我并没有想清 ...
- js 字符串拼接、截取、查找...
函数:split() 功能:使用一个指定的分隔符把一个字符串分割存储到数组 例子: let str=”020-88888888-03”; let arr=str.split(”-”); console ...
- C++之匿名对象解析
我们知道在C++的创建对象是一个费时,费空间的一个操作.有些固然是必不可少,但还有一些对象却在我们不知道的情况下被创建了.通常以下三种情况会产生临时对象: 1,以值的方式给函数传参: 2,类型 ...
- poj1275收银员——差分约束
题目:http://poj.org/problem?id=1275 做的第一道差分约束题... 首先,根据题意得出一些不等关系(f为前缀和雇佣人数): 0 <= f[i] - f[i-1] &l ...
- 17.for循环语句
for循环: 语法: for(表达式1;表达式2;表达式3){ java语句; } 表达式1是最初始化表达式:最先执行,只执行一次 表达式2必须是boolean 类型的表达式.结果为ture或者fal ...
- <正则吃饺子> :关于新项目的环境搭建(一)
来到新的公司,需要使用myeclipse.maven.svn.tomcat.mysql: 对于先前一直只用 netbeans 的我,在这里把环境搭建 的情况记录下来.来加深自己的学习和帮助后来者. 第 ...
- Andriod开发 --插件安装、环境配置、问题集锦
1.用Eclipse搭建Android开发环境和创建第一个Android项目(Windows平台) 链接阅读http://www.cnblogs.com/allenzheng/archive/2012 ...
- JAVA 数组的常用操作
目录: 声明数组: 初始化数组: 查看数组长度: 遍历数组: int数组转成string数组: 从array中创建arraylist: 数组中是否包含某一个值: 将数组转成set集合: 将数组转成li ...
- Flutter实战视频-移动电商-44.详细页_首屏自定义Widget编写
44.详细页_首屏自定义Widget编写 把详细页的图片.标题.编号和价格形成一个单独的widget去引用 详情页的顶部单独封装个插件 在pages下面新建detials_page的文件件并在里面新建 ...
- dataTables使用ajax请求显示数据
dataTables是一种很好用前端表格显示库.当加载大量数据时,可以用Ajax 获取数据来提高效率,增速网页加载速率.下面以一个例子作示范. 首先,需要下载jQuery以及dataTables库.这 ...