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;
}
上一篇:requests模块响应数据的三种方式


下一篇:数位拆解(从int获取每一位)