http://acm.hdu.edu.cn/showproblem.php?pid=3177
2 20 3 10 20 3 10 1 7 10 2 1 10 2 11
Yes No
<span style="font-size:18px;">#include<iostream> #include<cstdio> #include<algorithm> using namespace std; struct Node { int a,b; int c; }s[1005]; bool cmp(Node a,Node b) { return a.c>b.c; } int main() { int T,V,N,i; scanf("%d",&T); while(T--) { scanf("%d%d",&V,&N); for(i=0;i<N;i++) { scanf("%d%d",&s[i].a,&s[i].b); s[i].c=s[i].b-s[i].a; } sort(s,s+N,cmp); for(i=0;i<N;i++) { if(s[i].b>V) { printf("No\n"); break; } else V=V-s[i].a; } if(i==N) printf("Yes\n"); } return 0; } </span>
原文地址:http://blog.csdn.net/u012766950/article/details/37955745