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.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- RTMP协议的理解
RTMP协议:real time message protocol 工作原理: 先采集摄像头视频和麦克风音频信息,再进行音视频的编码(mpeg),通过FMLE(Flash Media Live Enc ...
- <十三>UML核心视图静态视图之业务用例图
一:uml的核心视图 --->如果说UML是一门语言,上一章学习的参与者等元素是uml的基本词汇,那么视图就是语法.uml通过视图将基元素组织在一起,形成有意义的句子. --->uml可视 ...
- c++再探string之eager-copy、COW和SSO方案
在牛客网上看到一题字符串拷贝相关的题目,深入挖掘了下才发现原来C++中string的实现还是有好几种优化方法的. 原始题目是这样的: 关于代码输出正确的结果是()(Linux g++ 环境下编译运行) ...
- 24.如何结束返回值是void的方法
如何结束返回值是void的方法? return;只能够出现在方法类型是void 的方法中,用来结束方法. return后面还可以跟数据,后面的数据可以是整数.字符串.false.ture.小数.主要看 ...
- DataWindow.NET 控件 实现点击列头排序
1.定义字段 Boolean ib_SetSort = true; string is_SortType = " ...
- SpringMVC注解说明
@controller 通过@controller标注即可将class定义为一个controller类. @RequestMapping value 表示需要匹配的url的格式. method 表示所 ...
- OpenFileDialog无法弹出的解决方法
今天在写一个socket通信的winform小程序,由于socket的receive方法会阻塞线程,所以就使用了多线程解决.但在新建的线程中创建OpenFileDialog并调用其ShowDialog ...
- Lotus and Characters (stronger)
题意: 有n类物品,第i种物品权值为$val(i)$,有$cnt(i)$个,现在你可以选出一些物品排成一个序列(假设有m个), 记第i个物品种类为$x_i$,最大化$\sum_{i=1}^m{i * ...
- CF 345A Mike and Frog
题目 自己歪歪的做法WA了好多发. 原题中每一秒都相当于 $x1 = f1(x1)$ $x2 = f2(x2)$ 然后这是一个定义域和值域都在[0,m-1]的函数,显而易见其会形成一个环. 而且环长不 ...
- ElasticSearch基础+文档CRUD操作
本篇博客是上一篇的延续,主要用来将年前学习ES的知识点做一个回顾,方便日后进行复习和汇总!因为近期项目中使用ES出现了点小问题,因此在这里做一个详细的汇总! [01]全文检索和Lucene (1)全文 ...