求助
查看原帖
求助
827873
abc1856896楼主2024/1/12 18:14
#include<bits/stdc++.h>
using namespace std;
const int MAX_N=10005;
int n,l,p;
int a[MAX_N],b[MAX_N]; 
int ans,pos,tank;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
	}
	cin>>l>>tank;
	n++;
	a[n]=l;
	b[n]=0;
	priority_queue<int> que;
	for(int i=1;i<=n;i++){
		int d=a[i]-pos;
		while(tank-d<0){
			if(que.empty()){
				cout<<-1;
				return 0;
			}
			tank+=que.top();
			ans++;
			que.pop();
		}
		tank-=d;
		que.push(b[i]);
		pos=a[i];
	}
	cout<<ans;
	return 0;
}

28分

2024/1/12 18:14
加载中...