码题集OJ-自驾游 (matiji.net)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int>PII;
#define x first
#define y second
const int N = 2010;
PII a[N];
int n, L, mx, s;
struct Car {
int distance;
int money;
int idx;
};
bool dfs() {
queue<Car> q;
q.push({0, s, -1});
while (!q.empty()) {
Car t = q.front();
q.pop();
if (t.distance + mx >= L)
return true;
for (int i = t.idx + 1; i <= n; i++) {
if (a[i].x > t.distance + mx)
break;
if (a[i].y > t.money)
continue;
q.push({a[i].x, t.money - a[i].y, i});
}
}
return false;
}
int main() {
while (cin >> n >> L >> mx >> s) {
for (int i = 0; i < n; i++)cin >> a[i].x >> a[i].y;
if (dfs())
puts("Yes");
else
puts("No");
}
return 0;
}