#include <bits/stdc++.h>
using namespace std;
const int maxm=2e4+5;
//n,补给节点数量
//l,长跑距离
//ma,体力值上限
//s,硬币数量
int n,l,ma,s;
struct Shop{
int p,c;//p距离,c花费
}a[maxm];
struct Node{
int now,s,id;//now当前距离,s剩下的钱,id当前商店位置
}st;
bool cmp(Shop x,Shop y){
if(x.p!=y.p)return x.p<y.p;//按距离起点从小到大排序
return x.c<y.c;//距离一样按花费排序
}
signed main(){
while(scanf("%d%d%d%d",&n,&l,&ma,&s)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d%d",&a[i].p,&a[i].c);
}
if(ma>=l)
{//如果直接就能到
cout<<"Yes"<<endl;
continue;
}
a[++n].p=l;//加入终点比较方便
a[n].c=0;
//排序
sort(a+1,a+1+n,cmp);
queue<Node>q;
st={0,s,0};
q.push(st);
int ok=0;
//bfs
while(!q.empty())
{
Node x=q.front();
q.pop();
if(x.now==l)
{//如果到了终点
ok=1;
break;
}
for(int i=x.id+1;i<=n;i++)
{
if(a[i].p-x.now>ma)
{
//大于体力值的地方不可能到
break;
//当前硬币数大于商店花费
}else if(x.s>=a[i].c)
{
Node t={a[i].p,s-a[i].c,i};
q.push(t);
}
}
}
puts(ok?"Yes":"No");
}
return 0;
}
长跑 bfs
最新推荐文章于 2024-06-12 10:00:23 发布