P2278 Code

P2278

#include <cstdio>
#include <queue>

struct task
{
	int number;
	int need;
	int get;
	int grade;
	inline bool operator < (const task &b) const
	{
		return this->grade<b.grade||(this->grade==b.grade&&this->get>b.get);
	}
};

std::priority_queue<task,std::vector<task>,std::less<task>> wait;

int main()
{
	int num,get,times,grade;
	int time=-1;
	while(scanf("%d%d%d%d",&num,&get,&times,&grade)!=EOF)
	{
		while((!wait.empty())&&time+wait.top().need<=get)
		{
			time+=wait.top().need;
			printf("%d %d\n",wait.top().number,time);
			wait.pop();
		}
		if(!wait.empty())
		{
			task cache=wait.top();
			wait.pop();
			cache.need-=get-time;
			wait.push(cache);
		}
		wait.push({num,times,get,grade});
		time=get;
	}
	while(!wait.empty())
	{
		time+=wait.top().need;
		printf("%d %d\n",wait.top().number,time);
		wait.pop();
	}
	return 0;
}

posted @ 2019-11-29 12:38  Macesuted  阅读(129)  评论(0编辑  收藏  举报