Crixalis's Equipment

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1854    Accepted Submission(s): 770

Problem Description
Crixalis - Sand King used to be a giant 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 has a volume of V units, and Crixalis has N equipment, each of them needs Ai units of space. When dragging his equipment into the hole, Crixalis finds that he needs more space to ensure everything is 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 are Bi units of space left. After it moved in, the volume of the hole will decrease by Ai. Crixalis wonders if he can move all his equipment into the new hole and he turns to you for help.

 

Input
The 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<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000.
 

Output
For each case output "Yes" if Crixalis can move all his equipment into the new hole or else output "No".
 

Sample Input
2

20 3
10 20
3 10
1 7

10 2
1 10
2 11

 

Sample Output
Yes
No
 

Source
 

Recommend
lcy
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node
{
    int a;
    int b;
    int c;
}p[1111];
bool cmp(Node x,Node y)
{
    return x.c>=y.c;
}
int main()
{
    int T;
    scanf("%d",&T);
while(T--)
{
    memset(p,0,sizeof(p));
    int n,v;
    scanf("%d%d",&v,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&p.a,&p.b);
        p.c=p.b-p.a;
    }
    sort(p,p+n,cmp);
    int OK=1;
    for(int i=0;i<n;i++)
    {
        if(v>=p.b)
        {
            v-=p.a;
        }
        else
        {
            OK=0;
            break;
        }
    }
    if(OK)
        puts("Yes");
    else
        puts("No");
}
    return 0;
}

HDOJ 3177 Crixalis&#39;s Equipment的更多相关文章

  1. 杭电 3177 Crixalis&#39;s Equipment

    http://acm.hdu.edu.cn/showproblem.php? pid=3177 Crixalis's Equipment Time Limit: 2000/1000 MS (Java/ ...

  2. HDU 3177 Crixalis&#39;s Equipment(贪婪)

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=3177 Problem Description Crixalis - Sand King used t ...

  3. hdu 3177 Crixalis&#39;s Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. Hdu 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDU ACM 3177 Crixalis's Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. 【hdu 3177 Crixalis's Equipment】 题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3177 \(describe\): 有一个山洞,山洞的容积最大为\(v\).现在你有\(n\)个物品,这 ...

  7. HDU 3177 Crixalis's Equipment (贪心,差值)

    题意:判断 n 件物品是否可以搬进洞里,每件物品有实际体积A和移动时的额外体积 B . 析:第一反应就是贪心,一想是不是按B从大到小,然后一想,不对,比如体积是20,第一个 是A=11, B=19.第 ...

  8. HDOJ 3966 Aragorn&#39;s Story

    树链拆分+树阵 (进入坑....) Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/327 ...

  9. hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

    题意:在一条直线上有n个点.取一长度差为x的区间. 规定点必须是区间的端点. 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举 ...

随机推荐

  1. The Rotation Game (POJ 2286) 题解

    [问题描述] (由于是英文的,看不懂,这里就把大意给大家说一下吧……都是中国人,相信大家也不愿意看英文……) 如图,一个井字形的棋盘,中间有着1-3任意的数,有ABCDEFGH八个操作,每个操作意味着 ...

  2. 1.html5究竟是什么

    1.html5的起源,历史背景…… 按照一般的套路,我这里应该对html5的起源和发展历史,其优越性等大书特书一番.但既然你有意识地专门去找类似的文章,说明你早有相应的认识,就算没有,类似的东西网上也 ...

  3. WARNING: /sys/kernel/mm/transparent_hugepage/enabled is

    安装MONGODB 3.0.6的时候提示警告信息,如下: 2015-09-09T11:04:35.011+0800 I CONTROL [initandlisten] ** WARNING: /sys ...

  4. 一篇文章教你读懂Makefile

    makefile很重要      什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professiona ...

  5. golang的nil

    golang中什么样的类型可以赋值nil? 类型文档中有注定"uninitialized value is nil"的类型都可以赋值nil. golang的基本类型不能赋值nil: ...

  6. IOS之表视图添加搜索栏

    下面是我们要实现的效果.本效果是在上一篇自定义表视图的基础上进行更改的.     1.将Search bar and search display拖动到ViewController中.不要添加Sear ...

  7. 与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。

    今天同学请教我数据库为什么打不开了,打开SQL Server 2008 的 SQL Server Management Studio,输入sa的密码发现,无法登陆数据库?提示以下错误: "在 ...

  8. EF简单的增删查改

    Add /// <summary> /// /// </summary> public void Add() { TestDBEntities2 testdb = new Te ...

  9. 如何在Swing窗体增删组件后及时刷新显示新界面

    转自:http://blog.csdn.net/leeshuqing/article/details/8636211 关键的四行代码,连续调用窗体的四个方法即可: repaint();validate ...

  10. < java.util >-- List接口

    List本身是Collection接口的子接口,具备了Collection的所有方法.现在学习List体系特有的共性方法,查阅方法发现List的特有方法都有索引,这是该集合最大的特点. List:有序 ...