题解:AT_abc455_c [ABC455C] Vanish
思路
记录每一种数的数量与其值的乘积(也就是删除一种数减少的值),然后每次就删除最大的乘积,剩下的就是答案。
代码
记录
#include<iostream>
#include<queue>
#include<map>
using namespace std;
typedef long long lld;
priority_queue<lld> q;
map<lld,int> m;
int main(){
int n,k,x;
cin>>n>>k;
for(int i = 1; i <= n; i++){
cin>>x;
m[x]++;
}
for(auto p : m){
q.push(p.first*p.second);
}
while(!q.empty() && k--){
q.pop();
}
lld s = 0;
while(!q.empty()){
s += q.top();
q.pop();
}
cout<<s;
return 0;
}