zoukankan      html  css  js  c++  java
  • UVA 11729 Commando War

    根据任务时间从大到小排序,保存当前士兵以后能够和其他人共同进行的时间。求出差的最大值,加上交代每个士兵任务这个必须时间就是答案。

    #include<cstdio>
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    using namespace std;
    struct node{int x,y;}man[1005];
    int last[1005];
    bool cmp(const node &a,const node &b)
    {
        return a.y>b.y;
    }
    int main()
    {
        int n;
        int cas=1;
        while(scanf("%d",&n)&&n)
        {
            int ans=0;
            int sum=0;
            last[n]=0;
            for(int i=1;i<=n;i++)
            {
                scanf("%d%d",&man[i].x,&man[i].y);
                sum+=man[i].x;
            }
            sort(man+1,man+1+n,cmp);
            for(int i=n-1;i>=1;i--)
            {
                last[i]=last[i+1]+man[i+1].x;
            }
            for(int i=1;i<=n;i++)
            {
                if(man[i].y>last[i]) ans=max(ans,man[i].y-last[i]);
            }
            printf("Case %d: %d
    ",cas++,ans+sum);
        }
        return 0;
    }
    


  • 相关阅读:
    codeforce1028A Find Square
    2018ccpc网络赛 Buy and Resell
    差分约束
    Lost Cows
    动态查询区间第k大
    疫情控制
    天天爱跑步
    次小生成树
    树上差分闇の連锁
    Stars in Your Window
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3289800.html
Copyright © 2011-2022 走看看