60 WA 求调
查看原帖
60 WA 求调
596333
Finality_1207楼主2024/11/27 20:56

60 WA

#include<bits/stdc++.h>
using namespace std;
long long n,m,x,y,f[200010];
vector<long long> v[200010];
struct sht{
	long long x,y;
}t;
struct rxy{
	long long s,t,id;
}a[200010];
bool operator < (const sht &x, const sht &y){
	return x.x>y.x;
}
priority_queue<sht> q,p;
bool cmp(rxy x,rxy y){
	return x.t<y.t;
}
int main(){
//	freopen("pa.in","r",stdin);
//	freopen("pa.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>x>>y,a[i].s=x,a[i].t=y,a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)t.x=0,t.y=i,q.push(t);
	for(int i=1;i<=n;i++){
		while(!q.empty()){
			t=q.top();
			if(t.x<=a[i].t) swap(t.x,t.y),p.push(t),q.pop();
			else break;
		}
		if(p.empty()){
			t=q.top();q.pop();
			t.x=t.x+a[i].s;
			f[t.y]++,v[t.y].push_back(a[i].id);
			q.push(t);
		}
		else{
			t=p.top();p.pop();
			f[t.x]++,v[t.x].push_back(a[i].id);
			swap(t.x,t.y);
			t.x=a[i].s+a[i].t;
			q.push(t);
		}
	}
	for(int i=1;i<=m;i++){
		cout<<f[i]<<' ';
		sort(v[i].begin(),v[i].end());
		for(int j=0;j<v[i].size();j++)
			cout<<v[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}
2024/11/27 20:56
加载中...