cf754 754D - Fedor and coupons
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的更多相关文章
- codeforces 754D. Fedor and coupons
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- CodeForces 754D Fedor and coupons (优先队列)
题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, ...
- CodeForces 754D Fedor and coupons ——(k段线段最大交集)
还记得lyf说过k=2的方法,但是推广到k是其他的话有点麻烦.现在这里采取另外一种方法. 先将所有线段按照L进行排序,然后优先队列保存R的值,然后每次用最小的R值,和当前的L来维护答案即可.同时,如果 ...
- Codeforces 390Div2-754D. Fedor and coupons(贪心+优先队列)
D. Fedor and coupons time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- 【codeforces 754D】Fedor and coupons
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces754D Fedor and coupons
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- D. Fedor and coupons 二分暴力
http://codeforces.com/contest/754/problem/D 给出n条线段,选出k条,使得他们的公共部分长度最大. 公共部分的长度,可以二分出来,为val.那么怎么判断有k条 ...
随机推荐
- 一个DBA的雄心壮志
math-liu, 一个甲方的DBA,同时他还有另外一个名字“怕提神”.在某甲方工作的他最近这几年如打了鸡血一般工作起来完全由拼命三郎的那股劲,据说能唯一使他感到一丝鼓励和安慰的是以下这两位大牛前辈. ...
- How to recover if NMC cound not connect
Some times we suddently find that the NMC can not login,. You would see the sybase database error if ...
- 再论谭浩强《C语言程序设计》
一些同学学不好C语言,把罪责归于“因为教材是谭浩强写的”实在是很滑稽. 谭浩强老先生 1934 年生,现在已经 80 岁了.他 1958 年从清华大学自动控制系毕业,那年 24 岁.要知道 C 语言那 ...
- ImageMagick 将PDF转图片命令
将 pdf 转一张图片 PS C:\Users\Microestc\desktop> magick convert -density -quality .pdf -append .jpeg ro ...
- natapp 内网穿透服务
参考文章:https://www.jianshu.com/p/91a321e584b8 参考文章:https://www.jianshu.com/p/c4cb8666c96a 一.什么是内网穿透 通过 ...
- Windows驱动开发-Device结构体
每个驱动程序会创建一个或多个设备对象,每个设备对象都会有一个指针指向下一个设备对象 Device结构体源码 typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATIO ...
- Python3中找不到xrange定义和不能用len(map())
问题1:python3中找不到xrange的定义,vscode中提示未定义 解决:改成range,因为python3中取消了vscode 问题2:python3中map函数返回的是迭代器,因此无法用l ...
- 【Android】在程序中使用触力反馈
触力反馈又名:hapticFeedbackEnabled 一般有两种实现方式 第一种是在XML布局文件里面设置 android:hapticFeedbackEnabled="true&quo ...
- NO28 第四关考试题
第4章 第4周课前测试考试题 4.1 定时任务规则的含义01 第1题 如果在某用户的crontab文件中有以下记录,该行中的命令多久执行一次(RHCE考试题)?( ) 30 4 * * 3 mycm ...
- Django-路由Routers-SimpleRouter-DefaultRouter使用方法
路由Routers 对于视图集ViewSet,我们除了可以自己手动指明请求方式与动作action之间的对应关系外,还可以使用Routers来帮助我们快速实现路由信息. REST framework提供 ...