https://www.luogu.org/problemnew/show/P2278

题解:

一个是还未开始的进程,另一个是按照优先级排序的等待进程;

每次做时比较两个序列的队头,如果是当前在运行的进程先结束,

则把此进程输出,并将其弹出优先队列;如果是下一个进程要开始,

则先结算当前在运行的进程的剩余时间,并将下一个进程加入优先队列;

(原来endl和‘\n’真的有本质的区别)

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=1500000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k;
int ans,cnt,flag,temp,sum;
int a[N];
char str;
struct node{
    int id,start,time,rank;
    bool operator <(const node &S)const{
        if(rank==S.rank)
            return start>S.start;
        return rank<S.rank;
    }
}e[N],tmp;
priority_queue<node>q;
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    cnt++;
    while(~scanf("%d%d%d%d",&e[cnt].id,&e[cnt].start,&e[cnt].time,&e[cnt].rank))
        cnt++;
    //cout<<cnt<<endl;
    cnt--;
    int pos=1;
    int now=1;
    for(int i=1;i<=cnt;i++){
        if(q.empty()){
            q.push(e[pos]);
            now=max(now,e[pos].start);
            pos++;
        }//cout<<q.top().start<<endl;
        while(now+q.top().time>e[pos].start&&pos<=cnt){
            tmp=q.top();//cout<<q.top().id<<endl;
            q.pop();
            tmp.time=tmp.time-e[pos].start+now;
            now=e[pos].start;
            q.push(tmp);
            q.push(e[pos]);
            now=max(now,q.top().start);
            pos++;

        }

        now=max(now,q.top().start)+q.top().time;
        cout<<q.top().id<<" "<<now<<'\n';

        q.pop();
    }
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}