题目链接:
Problem - 230A - Codeforces
解题思路:
用结构体排序就好,从最小的开始比较,大于就加上奖励,小于输出NO
下面是c++代码:
#include<iostream>
#include<algorithm>
using namespace std;
struct dragon {
int num;
int sum;
}a[1010];
bool cmp(dragon x, dragon y) {
return x.num < y.num;
}
int main()
{
int s, n;
cin >> s >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].num >> a[i].sum;
}
sort(a, a + n, cmp);
for (int i = 0; i < n; i++) {
if (s <= a[i].num) {
cout << "NO";
return 0;
}
else {
s += a[i].sum;
}
}
cout << "YES";
return 0;
}