题解:AT_wtf22_day1_a Save the Monsters
无论如何,英雄都会有
显然,保护一个怪物就必须全程保护它,否则等于没保护。易得贪心:按照怪物被攻击次数(需要保护次数)排序,从小到大保护。
按照上述策略保护怪兽
复杂度
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, x, buc[N], a, b;
signed main(){
cin >> n >> m >> a >> b;
for(int i = 1; i <= m; ++i) scanf("%d", &x), ++buc[x];
int cnt = 0;
sort(buc + 1, buc + 1 + n);
for(int i = 1, s = 0; i <= n; ++i){
s += buc[i];
if(s > b) break;
++cnt;
}
cout << n - min(n - cnt, a - b);
return 0;
}