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.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- Windows程序设计(1)——Win32运行原理(三)
进程控制 1 获得系统进程 2 终止当前进程 3 终止其他进程 4 进程控制 4.1 获得系统进程 使用toolhelp模块可以实现获取系统中当前运行当中的进程列表. 思路如下,使用CreateToo ...
- HDU3183 A Magic Lamp —— 贪心(单调队列优化)/ RMQ / 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3183 题解: 方法一:贪心. 在草稿纸上试多几次可以知道,删除数字中从左到右最后一位递增(可以等于)的 ...
- ansible 文件模块,很实用
摘自: http://blog.csdn.net/kellyseeme/article/details/50545521
- C#入门---1、C#装备知识(C#如何学习)
C#入门---1.C#装备知识(C#如何学习) 一.总结 一句话总结: 主视频,辅助书和教程:还是得看视频,直接看书或者看教程效率不高 1.C#和.NET的关系和区别? .net是一个平台,核心是.n ...
- redis-cluster的实例动态调整内存
当redis.conf中的最大内存配置为10G的时候,恰好程序已经写满了,但是物理主机是有内存的, 此时可以通过config set xxxx xxxx 来设置实例的内存大小,而不需要重启实例. 获取 ...
- BZOJ_1296_[SCOI2009]粉刷匠_DP
BZOJ_1296_[SCOI2009]粉刷匠_DP Description windy有 N 条木板需要被粉刷. 每条木板被分为 M 个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能 ...
- BZOJ_1095_[ZJOI2007]Hide 捉迷藏_动态点分治+堆
BZOJ_1095_[ZJOI2007]Hide 捉迷藏_动态点分治+堆 Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子 ...
- 洛谷 1541 乌龟棋——dp
题目:https://www.luogu.org/problemnew/show/P1541 以用了几张牌为阶段.注意知道了用了4种牌各几张后,当前位置就是确定的,所以不用记录什么的. #includ ...
- HDU2444(二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 23.java方法的深入
深入: public class MethodTest05{ public static void main(String[] args){ int i=m1(ture); System.out.pr ...