60pts 求调
查看原帖
60pts 求调
901195
__Luna__楼主2024/11/21 20:06
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node
{
	int s,t,r;
	node(int s=0,int t=0,int r=0):s(s),t(t),r(r){}
	bool operator<(node x){return t<x.t;}
}d[400005];
struct node2
{
	int r,t;
	node2(int r=0,int t=0):r(r),t(t){}
	bool operator<(node2 x)const{return t==x.t?r>x.r:t>x.t;}
};
priority_queue<node2>p;
priority_queue<node2>q;
vector<int>ans[400005];
int n,m;
signed main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>d[i].s>>d[i].t;
		d[i].r=i+1;
	}
	for(int i=0;i<m;i++)
	{
		p.push(node2(i,0));
	}
	sort(d,d+n);
	for(int i=0;i<n;i++)
	{
		int pr;
		while(!p.empty())
		{
			node2 pp=p.top();
			pr=pp.r;
			if(pp.t<=d[i].t)
			{
				q.push(node2(0,pr));
				p.pop();
			}
			else break;
		}
		if(!q.empty())pr=q.top().t,q.pop();
		else p.pop();
		ans[pr].push_back(d[i].r);
		p.push(node2(pr,d[i].s+d[i].t));
	}
	for(int i=0,j;i<m;i++)
	{
		cout<<(j=ans[i].size())<<" ";
		sort(ans[i].begin(),ans[i].end());
		for(int k=0;k<j;k++)
		{
			cout<<ans[i][k]<<" ";
		}
		cout<<endl;
	}
}
2024/11/21 20:06
加载中...