G题求助!

// Problem: why买外卖
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/67741/G
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
#include<map>
#include<cmath>
using namespace std;
#define endl '\n'
int _;
const int N=2e5+10;
using ll=long long;
using ULL=unsigned long long;
#define int long long

void solve(){
	ll n,m;  //n是个数,m是初始金钱
	cin>>n>>m;
	map<ll,ll> mapm;
	vector<ll> cnt(n+10);//记录数字,离散化
	for(int i=1;i<=n;++i){
		ll a,b;cin>>a>>b;
		cnt[i]=a;
		mapm[a]+=b;
	}
	ll lens=unique(cnt.begin()+1,cnt.begin()+1+n)-(cnt.begin()+1);
	sort(cnt.begin()+1,cnt.begin()+1+lens);
	vector<ll> ans(lens+1);//前缀和
	for(int i=1;i<=lens;++i){
		ans[i]=ans[i-1]+mapm[cnt[i]];
	}
	for(int i=lens;i>=1;--i){
		if(cnt[i]<=ans[i]+m){
			 cout<<ans[i]+m<<endl;return;
		}
	}
	cout<<m<<endl;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>_;
	while(_--){
		solve();
	}
	return 0;
}

全部评论
有可能是没排序??
点赞 回复 分享
发布于 2024-02-02 19:29 河南
样例都过了,但是评测通过百分之0
点赞 回复 分享
发布于 2024-02-02 18:06 广东

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务