题意:给你一个数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的更多相关文章

随机推荐

  1. linux mysql字符编码问题

    发布:thatboy   来源:脚本学堂     [大 中 小] 本文介绍下,linux环境中mysql字符编码问题的解决办法,有遇到mysql编码问题的朋友,可以参考下本文的介绍,希望对你有一定的帮 ...

  2. ios8.1.2耗电情况严重的解决方法

    打开cydia,搜索ifile(威锋源,版本2.1.0-1).打开ifile,进入路径/Applications.里面有许多程序文件,选择适当的进行禁用(ifile可以禁用程序的活动而不完全删除它,这 ...

  3. Custom template tags and filters

    Code layout Custom template tags and filters must live inside a Django app. If they relate to an exi ...

  4. jsp调用javabean出现错误HTTP Status 500 - Unable to compile class for JSP

    HTTP Status 500 - Unable to compile class for JSP:   type Exception report message Unable to compile ...

  5. 2014年度辛星html教程夏季版第一节

    从今天起开始在博客园开启自己的html教程啦,先从第一节开始把,首先推荐一个网站,就是http:/www.w3cschool.cc,这是一个公开的教学网站,但是它有一个问题,那就是虽然很全面,但是不是 ...

  6. 程序员老鸟写sql语句的经验之谈

    做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...

  7. 【原】jQuery编写插件

    分享一下编写设置和获取颜色的插件,首先我将插件的名字命名为jquery.color.js.该插件用来实现以下两个功能1.设置元素的颜色.2.获取元素的颜色. 先在搭建好如下编写插件的框架: ;(fun ...

  8. 第十二周项目一 教师兼干部类】 共建虚基类person

    项目1 - 教师兼干部类]分别定义Teacher(教师)类和Cadre(干部)类,采用多重继承方式由这两个类派生出新类Teacher_Cadre(教师兼干部).要求: (1)在两个基类中都包含姓名.年 ...

  9. 关于BootStrap下图标的显示问题

    我现在在做自己的毕业设计,用到了bootstrap的这一套css样式,说句心里话,这一套东西确实很好用,但是一个小问题足足浪费了我将近两个小时. 我的问题是:没有办法使用bootstrap下的图标(很 ...

  10. BZOJ 1640: [Usaco2007 Nov]Best Cow Line 队列变换

    Description FJ打算带着他可爱的N (1 ≤ N ≤ 2,000)头奶牛去参加"年度最佳老农"的比赛.在比赛中,每个农夫把他的奶牛排成一列,然后准备经过评委检验. 比赛 ...