2个多小时,弱智了。。(连A都做不对,就不要做D了(迷))

 #include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define LL long long
#define N 100005
#define M 1000005
#define mod 2147483648LL
#define inf 0x7ffffffff
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>''){if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<=''){x=x*+ch-''; ch=getchar();}
return x*f;
}
int n,k;
struct node{
int x,y,id;
}a[N<<];
bool cmp(node a, node b)
{
if (a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int ans,cnt;
int b[N<<],L,R;
set<pair<int , int > > q;
set<pair<int , int > >:: iterator it;
int main()
{
n=ra(); k=ra();
for (int i=; i<=n; i++)
a[i].x=ra(),a[i].y=ra(),a[i].id=i;
sort(a+,a+n+,cmp);
if (n==)//zz
{
cout<<a[].y-a[].x+<<endl;
cout<<"";
return ;
}
// for (int i=1; i<=n; i++)
// printf("%d %d %d\n",a[i].x,a[i].y,a[i].id);
q.insert(make_pair(a[].y,a[].id));
for (int i=; i<=n; i++)
{
pair<int , int > tmp,qwq;
tmp=*q.begin();
while (a[i].x>tmp.first && !q.empty())
{
q.erase(tmp);
tmp=*q.begin();
}
q.insert(make_pair(a[i].y,a[i].id));
if (q.size()>=k)
{
tmp=*q.begin();
if (ans<tmp.first-a[i].x+)
{
cnt=;
ans=tmp.first-a[i].x+;
L=a[i].x;
R=tmp.first;
}
q.erase(tmp); //这里比较有意思,这是最小的,只要记录的最小的是没有用了的,再加着反而会让结果变小
}
}
cout<<ans<<endl;
if (ans==)
{
for (int i=; i<=k; i++) cout<<i<<" ";
}
else
{
//cout<<L<<" "<<R<<endl;
for (int i=; i<=n; i++)
if (L>=a[i].x && R<=a[i].y && k) //tmd还能这么输出,真是尴尬啊、、、
cout<<a[i].id<<" ",k--;
}
return ;
}
//%%%%%%%%%%%%%%%%cf有数据就是好,面相数据编程233

cf754 754D - Fedor and coupons的更多相关文章

  1. codeforces 754D. Fedor and coupons

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. 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 ...

  3. CodeForces 754D Fedor and coupons (优先队列)

    题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, ...

  4. CodeForces 754D Fedor and coupons ——(k段线段最大交集)

    还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果 ...

  5. Codeforces 390Div2-754D. Fedor and coupons(贪心+优先队列)

    D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  6. 【codeforces 754D】Fedor and coupons

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. codeforces754D Fedor and coupons

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

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

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

  9. D. Fedor and coupons 二分暴力

    http://codeforces.com/contest/754/problem/D 给出n条线段,选出k条,使得他们的公共部分长度最大. 公共部分的长度,可以二分出来,为val.那么怎么判断有k条 ...

随机推荐

  1. iOS直播集成和问题总结(阿里云直播)

    https://www.jianshu.com/p/714ce954e628 最近接手公司的直播项目,对以前遗留的问题做处理和优化, 于是顺便看了下阿里云直播的文档,在下面写下对直播的理解和遇到的问题 ...

  2. 洛谷 P5242 [USACO19FEB]Cow Dating P

    这道题很有意思. 不难发现,对于一个区间 \([l, r]\),恰好只有一个奶牛接受邀请的概率为 \[\prod_{i=l}^r(1-p_i) \cdot \sum_{i=l}^r \frac {p_ ...

  3. B. Shortest Cycle 无向图求最小环

    题意: 给定 n 个点,每个点有一个权值a[i],如果a[u]&a[v] != 0,那么就可以在(u,v)之间连一条边,求最后图的最小环(环由几个点构成) 题解:逻辑运算 & 是二进制 ...

  4. 一个Java的小问题

    老师今天在讨论群里抛出了一个问题,让大家尝试思考一下他所给的一段代码输出是什么. 其代码如下: class T { void foo() { this.bar(); } void bar() { Sy ...

  5. [LuoguP1025][数据加强]数的划分

    原题连接:Click 加强数据:Click Solution 参考博客:Click 题目意思非常明确了,这是一道组合数学的题目.我就直接讲dp解法了. dp 题意可以转化为将\(n\)个苹果放进\(k ...

  6. 4.2 Scikit-Learn简介(机器学习篇)

    目录 第四章 机器学习 4.1 机器学习简介 4.1.1 机器学习分类 4.2 Scikit-Learn简介 4.2.1 Scikit-Learn的数据表示 4.2.2 Scikit-Learn的评估 ...

  7. 图解Mybatis框架原理及使用

    1.前言 努力学习完ssm框架之后,终于也成功的把三大框架的使用以及配置文件细节忘得一干二净.为了努力捡起来以及方便今后的复习,决定写一篇博客记录一下. 本博客的所有分析都是在持久层接口以及接口中的方 ...

  8. 解决modelsim破解在win10下无法生成license

    显示没有找到mgls.dll,此时,这个教程能够帮助你. 1.右击搜索结果cmd,选择以管理员身份运行 2. 打开win64(进入安装目录的win64),也就是两个破解文件所在的路径,输入cd win ...

  9. CSS-lineheight

    .test div{width:300px;margin:15px 0;border:1px solid #000;}.test p{margin:0;font-size:30px;}.fixed d ...

  10. django+centos+mariadb读写分离完美实现(上)-mysql主从备份实现

    首先画图一张,用来展示今天要做的事情,读写分离,个人理解就是使用mysql主从备份的原理,让两个数据库同时为自己提供服务.其中主库负责数据保存,从库负责数据展示,可以一主一从,也可以一主多从.从而降低 ...