zoukankan      html  css  js  c++  java
  • Hdu 4221 Greedy?

    Greedy?

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2300    Accepted Submission(s): 785

    Problem Description

    iSea is going to be CRAZY! Recently, he was assigned a lot of works to do, so many that you can't imagine. Each task costs Ci time as least, and the worst news is, he must do this work no later than time Di!
    OMG, how could it be conceivable! After simple estimation, he discovers a fact that if a work is finished after Di, says Ti, he will get a penalty Ti - Di. Though it may be impossible for him to finish every task before its deadline, he wants the maximum penalty of all the tasks to be as small as possible. He can finish those tasks at any order, and once a task begins, it can't be interrupted. All tasks should begin at integral times, and time begins from 0.

    Input

    The first line contains a single integer T, indicating the number of test cases.
    Each test case includes an integer N. Then N lines following, each line contains two integers Ci and Di.

    Technical Specification
    1. 1 <= T <= 100
    2. 1 <= N <= 100 000
    3. 1 <= Ci, Di <= 1 000 000 000

    Output

    For each test case, output the case number first, then the smallest maximum penalty.

    Sample Input

    2

    2

    3 4

    2 2

    4

    3 6

    2 7

    4 5

    3 9

    Sample Output

    Case 1: 1

    Case 2: 3

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    struct node{
        int x;
        int y;
    }w[100005];
    int t,n;
    
    int cmp(node a,node b)
    {
        if(a.y<b.y)
            return true;
        return false;
    }
    
    int main()
    {
        scanf("%d",&t);
        int tcase=1;
        while(t--)
        {
            scanf("%d",&n);
            for(int i=0;i<n;i++)
            {
                scanf("%d%d",&w[i].x,&w[i].y);
            }
            sort(w,w+n,cmp);
            
            long long sum=0,max=0;
            for(int i=0;i<n;i++)
            {
                sum+=w[i].x;
                if(max<sum-w[i].y)
                    max=sum-w[i].y;
            }
            printf("Case %d: %lld
    ",tcase++,max);
        }
        return 0;
    }
    

      

  • 相关阅读:
    小程序 中 自定义单选框样式
    自定义checkbox和radio的样式
    postgre修改字段数据类型
    xpat如何获取一个标签里的属性值
    一看就明白的爬虫入门讲解:基础理论篇
    第一天
    poj 1979 走多少个‘ . '问题 dfs算法
    ACM 贪心算法总结
    poj 2393 奶牛场生产成本问题 贪心算法
    poj 3262 牛毁坏花问题 贪心算法
  • 原文地址:https://www.cnblogs.com/zhangliu/p/7063229.html
Copyright © 2011-2022 走看看