题意:给你一个数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. PHP 易出问题记录

    PHP foreach引用缺陷 <?php $array = array(1, 2, 3); foreach ($array as &$v) {} foreach ($array as ...

  2. 经典的C程序

    程序一:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数 #include<stdio.h> void main(){ int a, b, c, i; ; ...

  3. Instructions Set JAVA_HOME System-Wide

    Instructions Set JAVA_HOME System-Wide 1 Start a root terminal session and then change directories t ...

  4. iOS开发者计划(转)

    苹果对软件和开发者的管理十分严格,你只有加入了Apple Developer计划之后,才能将你的软件放到真机上运行或者发布到App Store上去.这种方法看似麻烦,但是却有效的解决了盗版和劣质软件充 ...

  5. UML 类图的关系

    1.  关联关系 1.1 单向关联 . public class ClassA { private ClassB bVar; } public class ClassB { //... } 1.2  ...

  6. CAS单点登录配置[5]:测试与总结

    终于要结束了... 测试 1 我们同时打开Tomcat6和Tomcat7,如果报错请修改. 打 开浏览器,输入http://fighting.com/Client1,进入CAS登录界面,这里我们先输入 ...

  7. AD10 gerber生成,及导入cam350 多图详细步骤

    Protel99转Gerber文件导入到CAM350中看为什么钻孔层偏位 这是因为你导入CAM350 时的格式没有设置正确.你用PROTEL 导出钻孔 TXT 时记住是什么格式,例如: 2:3,2:4 ...

  8. 最简单的CRC32源码---逐BIT法

    CRC其实也就那么回事,却在网上被传得神乎其神.单纯从使用角度来说,只需要搞明白模二除法,再理解一些偷懒优化的技巧,就能写出自己的CRC校验程序. 下面的代码完全是模拟手算过程的,效率是最低的,发出来 ...

  9. 2.5.6 使用progressDialog创建进度对话框

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  10. SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '/tmp/ClientActionTrack2015112511.txt' 不堵塞事务

    mysql> insert into ClientActionTrack20151125(clientSn,ip,url,httpMethod,requestParams,requestHead ...