13T 3W 求调
查看原帖
13T 3W 求调
1044428
crane_in_clear_sky楼主2025/2/2 15:39

记录:https://www.luogu.com.cn/record/201065835

代码

#include<bits/stdc++.h>
using namespace std;
const int N=1E5*2+1;
long long n,d,x;
struct node{
	long long pos,inc;
};
vector<node> res;
node ss[N];
long long sum;
long long ans;
inline bool cmp(node x,node y){
	if(x.inc==y.inc) return x.pos<y.pos;
	return x.inc>y.inc;
}
int main(){
	scanf("%lld%lld%lld",&n,&d,&x);
	if(d>=x){
		putchar('0');
		return 0;
	}
	for(int i=1;i<=n;i++) scanf("%lld",&ss[i].pos);
	for(int i=1;i<=n;i++) scanf("%lld",&ss[i].inc),res.push_back(ss[i]),ans+=ss[i].inc;
	if(ans+d<x){
		printf("-1");
		return 0;
	}
	sort(res.begin(),res.end()-1,cmp);
	for(int i=1;i<=n;i++){
		for(int j=0;j<res.size();j++){
			if(d>=res[j].pos){
				sum++;
				d+=res[j].inc;
				if(d>=x){
					printf("%lld",sum);
					return 0;
				}
				res.erase(res.begin()+j);
				break;
			}
			if(j==res.size()-1){
				printf("-1");
				return 0;
			}
		}
	}
	printf("-1");
	return 0;
}  
2025/2/2 15:39
加载中...