You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 105;
ll a[N], b[N];
bool done[N];
int main()
{
ll n, r;
scanf("%lld%lld", &n, &r);
for (int i = 0; i < n; i++) scanf("%lld%lld", a + i, b + i);
for (int j = 0; j < n; j++)
{
ll id = -1, cur = INT_MIN, cur2 = INT_MIN;
for (int i = 0; i < n; i++)
if (!done[i] && a[i] <= r && b[i] > cur)
cur = b[id = i];
if (id == -1) return puts("NO"), 0;
if (cur < 0)
for (int i = 0; i < n; i++)
if (!done[i] && a[i] <= r && (a[i] > cur || (a[i] == cur && b[i] > cur2)))
id = i, cur = a[i], cur2 = b[i];
r += b[id], done[id] = true;
if (r < 0) return puts("NO"), 0;
}
puts("YES");
return 0;
}