堆 模拟
搞个双关键字堆瞎模拟就好了。
代码:
#include<queue>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define F inline
#define N 15005
using namespace std;
struct pro{ int id,s,t,x; }tmp;
priority_queue <pro> q;
int lst,t;
F char readc(){
static char buf[100000],*l=buf,*r=buf;
if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
return l==r?EOF:*l++;
}
F int _read(){
int x=0; char ch=readc();
while (!isdigit(ch)&&ch!=EOF) ch=readc();
if (ch==EOF) return -1;
while (isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=readc();
return x;
}
F bool read(pro &a){
int id=_read(),s=_read(),t=_read(),x=_read();
if (~id) return a=(pro){id,s,t,x},1; return 0;
}
F void writec(int x){ if (x>9) writec(x/10); putchar(x%10+48); }
F void _write(int x,bool f){ writec(x),putchar(f?' ':'\n'); }
F bool operator <(pro a,pro b){ return a.x==b.x?a.s>b.s:a.x<b.x; }
int main(){
while (read(tmp)){
t=tmp.s-lst;
while (!q.empty()){
pro tp=q.top(); q.pop();
if (tp.t>t){ tp.t-=t,lst+=t,q.push(tp),t=0; break; }
else t-=tp.t,lst+=tp.t,_write(tp.id,1),_write(lst,0);
}
lst+=t,q.push(tmp);
}
while (!q.empty())
lst+=(tmp=q.top()).t,q.pop(),_write(tmp.id,1),_write(lst,0);
return 0;
}