1 条题解

  • 1
    @ 2022-7-29 21:07:20
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    struct Fw{
    	int a,b;
    	bool operator < (Fw o)const{
    		return b > o.b;
    	}
    }w[100001],a[100001];
    int n,k,mx[100001],sum;
    long long res;
    bool vis[100001];
    
    int main(){
    	res = 0;
    	scanf("%d %d",&n,&k);
    	for(int i = 1;i <= n; ++i){
    		scanf("%d",&w[i].a);
    	}
    	for(int i = 1;i <= n; ++i){
    		scanf("%d",&w[i].b);
    		res += w[i].b;
    	}
    
    	for(int i = 1;i <= n; ++i){
    		mx[w[i].a] = w[mx[w[i].a]].b < w[i].b ? i : mx[w[i].a];
    	}
    
    	for(int i = 1;i <= k; ++i){
    		res -= w[mx[i]].b;
    		if(w[mx[i]].b) ++sum;
    		vis[mx[i]] = true;
    	}
    
    	int l = 0;
    	for(int i = 1;i <= n; ++i){
    		if(!vis[i]){
    			a[++l] = w[i];
    		}
    	}
    
    	sort(a+1,a+1+l);
    	for(int i = 1;i <= l - (k - sum); ++i){
    		res -= a[i].b;
    	}
    	printf("%lld\n",res);
    	return 0;
    }
    
    • 1

    信息

    ID
    2226
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    99
    已通过
    16
    上传者