Dragons
http://codeforces.com/problemset/problem/230/A
所以直接贪心就行了。
AC代码:
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct Node { int x,y; }g[1010]; bool cmp(Node a, Node b) { return a.x < b.x; } int main() { int n,s,i; while(scanf("%d%d",&s,&n)!=EOF) { for(i = 0; i < n; i++) { scanf("%d%d",&g[i].x,&g[i].y); } sort(g,g+n,cmp); for(i = 0; i < n; i++) { if(s > g[i].x) { s+=g[i].y; } else { break; } } if(i == n) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }