社区讨论

60pts求调

P11289【MX-S6-T1】「KDOI-11」打印参与者 3已保存回复 6

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@mhk6whlv
此快照首次捕获于
2025/11/04 14:30
4 个月前
此快照最后确认于
2025/11/04 14:30
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200010;
struct node{
	int s,t,xu;
	bool operator<(const node &T) const{
		return t<T.t;
	}
};
node wen[N];
int n,m;
vector<int> res[N];
priority_queue<int,vector<int>,greater<int> > res1;
struct node1{
	int t,xu; 
};
struct cmp{
	bool operator()(const node1 &x,const node1 &y){
		if(x.t==y.t) return x.xu<y.xu;
		else return x.t>y.t; 
	}
};

signed main(){
//	freopen("print4.in","r",stdin);
//	freopen("print.out","w",stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) {
	cin>>wen[i].s>>wen[i].t;
	wen[i].xu=i;	
	}
	sort(wen+1,wen+n+1);
	priority_queue<int,vector<int>,greater<int> > p;
	priority_queue<node1,vector<node1>,cmp> q;
	for(int i=1;i<=m;i++){
		p.push(i);
	}
	for(int i=1;i<=n;i++){
		while(!q.empty()&&q.top().t<=wen[i].t) p.push(q.top().xu),q.pop();

		if(!p.empty()){
			int x=p.top();
			p.pop();
			res[x].push_back(wen[i].xu);
			q.push({wen[i].s+wen[i].t,x});
		}
		else{
			node1 x=q.top();
			q.pop();
			res[x.xu].push_back(wen[i].xu);
			q.push({wen[i].s+x.t,x.xu});
		}
		
	}
	for(int i=1;i<=m;i++){
		cout<<res[i].size()<<" ";
		sort(res[i].begin(),res[i].end());
		
		for(int x:res[i]) cout<<x<<" ";
		cout<<"\n";
	}

	return 0;
}

回复

6 条回复,欢迎继续交流。

正在加载回复...