I - Strength HDU - 6563

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
const int maxn=1e5+100;
typedef long long ll;
using namespace std;
int a[maxn],b[maxn],cnt,visit[maxn];//cnt来记录防御态的个数
struct Node
{
    int value,pos;
    bool operator <(const Node &d)const
    {
        return value<d.value;
    }
} node[maxn];
int main()
{
    int t,n,m;
    scanf("%d",&t);
    int kase=0;
    ll sum=0,sum1=0;;
    while(t--)
    {
        scanf("%d%d",&n,&m);
        memset(visit,0,sizeof(visit));
        sum=0;
        sum1=0;
        cnt=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        for(int i=0; i<m; i++)
            scanf("%d",&node[i].value);
        for(int i=0; i<m; i++)
        {
            scanf("%d",&node[i].pos);
            if(!node[i].pos)
                sum1+=node[i].value;
            if(node[i].pos)
                b[cnt++]=node[i].value;
        }
        ll ans,ans1;
        ans=ans1=0;
        //是否可以全部干掉
        sort(node,node+m);
        sort(a,a+n);
        int flag=0;
        if(n>=m)
        {
            int i,j;
            i=n-1;
            j=m-1;
            for(; i>=0&&j>=0; i--)
            {
                if(node[j].value<=a[i])
                    j--;
                else
                    break;
                if(!j)
                    break;
            }
            if(!j)
                flag=1;
        }
        if(flag)
        {
            int j=0;
            for(int i=0; i<n&&j<cnt; i++)
            {
                if(a[i]>=b[j])
                {
                    j++;
                    sum-=a[i];
                }
            }
            if(j!=cnt)
                flag=0;
            else
                ans=sum-sum1;
        }
        int i=n-1,j=0;
        for(; i&&j<m; i--)
        {
            if(a[i]>=node[j].value)
            {
                if(!node[j].pos)
                {
                    ans1+=(a[i]-node[j].value);
                }
                j++;
            }
            else
                break;
        }
        printf("Case %d: %lld\n",++kase,max(ans,ans1));
    }
    return 0;
}

  

This question is very interesting

First, the meaning of problems unknown (ha ha)

He has a defensive state, after all kill each other in order to fight each other directly blame

In both cases

1, do not all kill each other (with their own side of the large dry the other side of the smallest, with the second largest dry the other side the next smallest, until I can not be)

2, all kill each other (to get rid of state defense with minimum cost, and then subtract all the rest of the strange and the rest on the line)

Guess you like

Origin www.cnblogs.com/zhangzhenjun/p/12229839.html