cf754D
题意:给你一个数m,有多少优惠券,给个n,主角想用多少优惠券。然后接下来时m行,每行两个数,那张优惠券的优惠区间a,b(在a号货物到b号货物之间的所有都可以优惠)
问你,能不能用k张优惠券,是他的优惠区间重叠的部分最大。
今天第一次看优先队列,居然还有这么神奇的东西,omg,太强了
思路就是排序,然后用优先队列乱搞一下。。。
接下来给出代码
#include <iostream>
#include <queue>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int Maxn = 2147483647;
struct Node{
int l,r;
int i;
}node[300010];
bool cmp( const Node &a,const Node &b ){
return ( a.l == b.l ? a.r < b.r:a.l < b.l );
}
int main(){
int m,n;
scanf("%d%d",&m,&n);
for( int i = 1; i <= m; i++ ){
scanf("%d%d",&node[i].l,&node[i].r);
node[i].i = i;
}
sort( node+1,node+1+m,cmp );
priority_queue<int,vector<int>,greater<int> > q;
int inf = -Maxn;
int x;
int l,r;
for( int i = 1; i <= m; i++ ){
x = node[i].l;
q.push( node[i].r );
while( q.top() < x || q.size() > n ){
q.pop();
}
if( q.size() == n ){
if( inf < q.top() - x + 1 ){
inf = q.top() - x + 1;
l = x,r = q.top();
}
}
}
if( inf == - Maxn ){
cout << '0' << endl;
for( int i = 1; i <= n; i++ ){
printf( "%d ",i );
}
printf( "\n" );
exit(0);
}else{
cout << inf << endl;
for( int i = 1; i <= m; i++ ){
if( node[i].l <= l && node[i].r >= r ){
printf("%d ",node[i].i);
n--;
if( n == 0 ){
cout << '\n';
exit(0);
}
}
}
}
}
cf754D的更多相关文章
随机推荐
- 简易ORM(基于注解)
这是从我们现有项目做的一定的改进准备做成IDE插件 类似getter和setter的生成 1.定义实体类 通过注解说明其表名和字段名(SOURCE类型的注解 不需要运行时使用)@TableName(& ...
- Sqlserver 原生 MD5 函数(转)
--创建md5函数CREATE FUNCTION [dbo].[MD5](@src varchar(255) )RETURNS varchar(255)ASBEGIN DECLARE @md5 ...
- 水晶報表中小寫變大寫的函數-VB
Function total (ls as number) as string dim dx_sz as string dim dx_dw as string dim str_int as strin ...
- Docker入门
-----------------------------------------Docker入门教程(一)介绍Docker入门教程(二)命令Docker入门教程(三)DockerFileDocker ...
- Xcode8和iOS10的适配问题
本文转自:http://www.jianshu.com/p/90d5323cf510 =================== 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功 ...
- Central Europe Regional Contest 2012 Problem c: Chemist’s vows
字符串处理的题目: 学习了一下string类的一些用法: 这个代码花的时间很长,其实可以更加优化: 代码: #include<iostream> #include<string> ...
- 网页增重不可控?试试 OneAPM Cloud Test
再次发生了!HTTP Archive 报告在收集了 50 万个最受欢迎的网站的技术信息,经过整理分析后指出:2015 年,网页的平均「体重」增加了 16%,达到了 2,262 KB,近似于 2014 ...
- PYTHON--CLASS
class Robot: population = 0 def __init__(self, name): self.name = name print("(Initializing {0} ...
- USB做Host的OTG原理
在介绍USBOTG的基础上,着重介绍Maxim公司的MAX3301E型USBOTG电路的特点.内部结构和工作原理. 1 引言 随着USB2.0版本的发布,USB越来越流行,已经成为一种标准接口.现在, ...
- 转载:遍历Map的四种方法
http://www.cnblogs.com/kristain/articles/2033566.html 遍历Map的四种方法 public static void main(String[] ar ...