10pts求助
查看原帖
10pts求助
523541
Onana_in_XMFLS楼主2022/7/15 11:49
// Problem: P2278 [HNOI2003]操作系统
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2278
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define mem(arr,val) memset((arr),(val),(sizeof(arr)))
using namespace std;
struct com {LL num,intime,dotime,tip;};
bool operator<(com a,com b) {return a.tip!=b.tip?a.tip<b.tip:a.intime>b.intime;}
priority_queue <com> wait;
int main(int argc,char *argv[])
{
	LL a,b,c,d,t = 0;
	while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d))
	{
		while(!wait.empty() && t+wait.top().dotime <= b)
		{
			com tmp = wait.top();
			wait.pop();
			printf("%lld %lld\n",tmp.num,tmp.intime+tmp.dotime);
			t += tmp.dotime;
		}
		if(!wait.empty())	
		{
			com tmp = wait.top();
			wait.pop();
			tmp.dotime = tmp.dotime-b+t;
			wait.push(tmp);
		}
		wait.push((com){a,b,c,d});
		t = b;
	}
	while(!wait.empty())
	{
		com tmp = wait.top();
		wait.pop();
		t += tmp.dotime;
		printf("%lld %lld\n",tmp.num,t);
	}
	return 0;
}
2022/7/15 11:49
加载中...