其他分享
首页 > 其他分享> > HDU-6563 Strength (贪心)

HDU-6563 Strength (贪心)

作者:互联网

int T, n, m;
struct node{
    ll s, v;
}a[N], b[N];

bool cmp(const node&x, const node&y){
    return x.s < y.s;
}

int main()
{
    scanf("%d",&T);
    for(int Case = 1; Case <= T; ++ Case){
        scanf("%d%d",&n,&m);
        int num = 0;
        rep(i,1,n) scanf("%lld",&a[i].s);
        rep(i,1,m) scanf("%lld",&b[i].s);
        rep(i,1,m) {
            scanf("%lld",&b[i].v);
        }
        ll res1 = 0, res2 = 0;
        int l = 1, r = n;
        sort(a + 1, a + n + 1,cmp);
        sort(b + 1, b + m + 1, cmp);
        while(l <= m && r >= 1){
            while(b[l].v && l <= m) l ++;
            if(l > m || b[l].s > a[r].s) break;
            res1 += (a[r].s - b[l].s);
            r --;
            l ++;
        }
        l = m, r = n;
        while(l > 0 || r > 0){
            if(!r) break;
            if(a[r].s < b[l].s){
                res2 = 0;
                break;
            }
            else if(!b[l].v){
                res2 += a[r].s - b[l].s;
            }
            else if(!l) res2 += a[r].s;
            if(l) l --;
            if(r) r --;
        }
        printf("Case %d: %lld\n",Case,max(res1,res2));
    }
    return 0;
}

标签:Case,node,HDU,Strength,const,res2,6563,break,int
来源: https://www.cnblogs.com/A-sc/p/12878271.html