Crixalis ' s equipment

Source: Internet
Author: User

Crixalis ' s equipment
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3529 Accepted Submission (s): 1060
Problem Descriptioncrixalis-sand King used to be a giant scorpion (scorpion) in the deserts of Kalimdor. Though He's a guardian of Lich King now, he keeps the living habit of a scorpion like living underground and digging holes .
Someday Crixalis decides to move to another nice place and build a new house for himself (actually it ' s just a new hole). As he collected a lot of equipment, he needs to dig a hole beside his new house to store them. This hole have a volume of V units, and Crixalis have N equipment, each of them needs Ai units of space. When dragging him equipment into the hole, Crixalis finds that he needs more space to ensure everything are placed well. Actually, the ith equipment needs Bi units of space during the moving. More precisely crixalis can not move equipment into the hole unless there is Bi units of space left. After it moved in, the volume of the hole would decrease by Ai. Crixalis wonders if he can move all him equipment into the new hole and he turns to your for help. 
Inputthe first line contains an integer T, indicating the number of test cases. Then follows T cases, each one contains N + 1 lines. The first line contains 2 integers:v, volume of a hole and N, number of equipment respectively. The next n lines contain n pairs of Integers:ai and Bi. 0<t<=, 0<v<10000, 0<n<1000, 0 <Ai< V, Ai <= Bi < 1000.
Outputfor each case output "Yes" if Crixalis can move all his equipment into the new hole or else output "No".
Sample Input
220 310 203 101 710 21 102 11
Sample Output
YesNo

Greedy topic:

# include <iostream># include<cstdio># include<algorithm>using namespacestd;structinfo{intA, B;} a[2001];intCMP (Info A, info B)
{ returnA.A + b.b < B.A +a.b;}intMain () {intT; scanf ("%d", &t); while(t--) { intV, n, sum; scanf ("%d%d", &v, &N); Sum=v; intFlag =1; for(inti =0; I < n; i++) scanf ("%d%d", &AMP;A[I].A, &a[i].b); Sort (A, a+N, CMP); for(inti =0; I < n; i++) { if(a[i].b>sum) {Flag=0; Break; } Else{sum-=a[i].a; Flag=1; } } if(flag) cout<<"Yes"<<Endl; Elsecout<<"No"<<Endl; } return 0;}

Crixalis ' s equipment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.