The sol to print
https://oier.team/problems/93
思路
用两个优先队列。
一个用于存储没有打印任务的打印机,一个存储有任务的打印机。
如果有打印机没有打印任务直接选择里面最小的。
否则,找到等待时间最小的那一个。
Code
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200010;
#define int long long
int n,m;
struct node{int s,t,id;}a[maxn];
bool cmp(node &A,node &B){return A.t<B.t;}
struct print{int id,t;bool operator < (const print &x)const{return t==x.t ? id>x.id : t>x.t;}
};
priority_queue <print> q;
priority_queue <int,vector<int>,greater<int> > v;
priority_queue <int,vector<int>,greater<int> > ans[maxn];
int read(){int x=0,f=1;char c=getchar_unlocked();while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar_unlocked();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar_unlocked();}return x*f;
}
signed main(){freopen("print.in","r",stdin);freopen("print.out","w",stdout);int n = read(),m = read();for(int i = 1;i <= n;i++) a[i].s = read(),a[i].t = read(),a[i].id=i;sort(a+1,a+1+n,cmp);for(int i = 1;i <= m;i++) v.push(i);for(int i = 1;i <= n;i++){while(q.size() && q.top().t <= a[i].t)v.push(q.top().id),q.pop();if(v.empty()) ans[q.top().id].push(a[i].id),q.push({q.top().id,q.top().t+a[i].s}),q.pop();else ans[v.top()].push(a[i].id),q.push({v.top(),a[i].s+a[i].t}),v.pop();}for(int i = 1;i <= m;i++){printf("%d ",ans[i].size());for(int j = 0;j < ans[i].size();j++){while(!ans[i].empty()){printf("%d ",ans[i].top());ans[i].pop();} }printf("\n");}return 0;
}