BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站

难度在于读题

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int,vector<int>,greater<int> > q;
struct node{
	int l,r;
}e[1000005];
bool cmp(node a,node b){
	return a.l<b.l;
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[i]=(node){x,x+y};
	}
	sort(e+1,e+n+1,cmp);
	q.push(e[1].r+m);
	int ans=0;
	for (int i=2; i<=n; i++){
		while (!q.empty() && q.top()<e[i].l) q.pop();
		if (!q.empty()){
			int now=q.top();
			if (e[i].l>=now-m){
				ans++;
				q.pop();
			}
		}
		q.push(e[i].r+m);
	}
	printf("%d\n",ans);
	return 0;
}

  

posted @ 2018-10-19 21:02  ~Silent  阅读(204)  评论(0编辑  收藏  举报
Live2D