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条 ...
随机推荐
- PHP PDO_MYSQL 链式操作 非链式操作类
<?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +-------------------------------------- ...
- 「CH6202」黑暗城堡
「CH6202」黑暗城堡 传送门 这道题是要让我们求以点 \(1\) 为源点的最短路树的方案数. 我们先跑一遍最短路,然后考虑类似 \(\text{Prim}\) 的过程. 当我们把点 \(x\) 加 ...
- Python 基础之面向对象之常用魔术方法
一.__init__魔术属性 触发时机:实例化对象,初始化的时候触发功能:为对象添加成员,用来做初始化的参数:参数不固定,至少一个self参数返回值:无 1.基本用法 #例:class MyClass ...
- 设计模式课程 设计模式精讲 22-2 备忘录模式coding
1 代码演练 1.1 代码演练1 1 代码演练 1.1 代码演练1 需求: 网站笔记需要存储快照,能实现回退的功能. 注意: a 设计的时候,可以分为笔记类,笔记快照类和 笔记快照管理类 三个类. ...
- Python - 列表与字符串的相互转换
1. 列表转换成字符串,用''.join() # 创建一个列表 list1 = ['a','b','c'] # 将列表的元素拼接为字符串 print(''.join(list1)) # 将列表的元素通 ...
- 本周总结(19年暑假)—— Part5
日期:2019.8.11 博客期:111 星期日
- HTTP报文结构及Cookie、session区别
目录 万维网 HTTP超文本传输协议 特点 HTTP的报文结构. 下面介绍http请求报文最主要的一些特点 在服务器上存放用户的信息(Cookie) 实例: 工作原理: cookie中的主要内容: C ...
- java中的 RSA加密
package com.cn.test.rsa; import java.math.BigInteger; import java.security.KeyFactory; import java.s ...
- 二十、oracle通过复合索引优化查询及不走索引的8种情况
1. 理解ROWID ROWID是由Oracle自动加在表中每行最后的一列伪列,既然是伪列,就说明表中并不会物理存储ROWID的值:你可以像使用其它列一样使用它,只是不能对该列的值进行增.删.改操作: ...
- Linux centos7 sed工具介绍
一.sed上 grep工具功能只能实现查找,不能把查找的内容替换. sed本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行查找.删除.替换字符或字符串.调换字符串位置.直接修改文件内容等 ...