蒟蒻求调
查看原帖
蒟蒻求调
808286
m_k_n楼主2024/9/18 18:58

#8#9#10#13没过,用的贪心

#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Node{
	int x,t;
	bool operator<(const Node &Noode)const{
		return x+t<Noode.x+Noode.t;
	}
	Node(int xx,int tt):x(xx),t(tt){}
};
priority_queue<Node,vector<Node>,less<Node> > q;
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int x,t;
		cin>>x>>t;
		if(x+t<=m) q.push(Node(x,t));
	}
	int noww=0,sum=0,ans=0;
	while(sum<=m&&!q.empty()){
		Node s=q.top();
		q.pop();
		if(s.x>noww) noww=s.x;
		if(sum+noww+s.t<=m){
			sum+=s.t;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}
2024/9/18 18:58
加载中...