能力值越高自然更好,所以应该先杀能杀掉的龙再去杀剩下的。
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#define MAX 105
#define INF 0x3f3f3f3f
using namespace std;
struct dragon {
int x, y;
}a[1005];
bool cmp(const dragon& a, const dragon& b) {
return a.x < b.x;
}
int main() {
freopen("a.txt", "r", stdin);
freopen("b.txt", "w", stdout);
int s, n;
cin >> s >> n;
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i].x, &a[i].y);
}
sort(a, a + n, cmp);
bool f = true;
for (int i = 0; i < n; ++i) {
if (s > a[i].x) s += a[i].y;
else f = false;
}
if (f) cout << "YES";
else cout << "NO";
return 0;
}