求问这样的代码怎么判-1
查看原帖
求问这样的代码怎么判-1
793625
Pink_Cut_Tree楼主2023/12/17 21:37
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+3;
int n;
struct work{
	int spend,deadl;
	friend bool operator<(work x,work y){
		return x.deadl<y.deadl;
	}
}w[N];
bool check(int x){
	int t=x;
	for(int i=1;i<=n;i++){
		t+=w[i].spend;
		if(t>w[i].deadl){
			return 0;
		}
	}
return 1;
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>w[i].spend>>w[i].deadl;
	}
	sort(w+1,w+n+1);
	int l=1,r=1.5e6,mid,ans;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)){
			l=mid+1,ans=mid;
		}
		else{
			r=mid-1;
		}
	}
	cout<<ans;
return 0;
}

2023/12/17 21:37
加载中...