蓝桥杯国赛——对局匹配
作者:
amagi
,
2024-05-11 19:57:21
,
所有人可见
,
阅读 7
动态规划 贪心
#include <bits/stdc++.h>
#define ll long long
const ll N = 1e6;
ll op[N];
ll dp[N];
bool ok[N];
std::map<ll,ll> pp;//统计每个数出现的次数
int main(){
ll n,k;
std::cin >> n >> k;
ll ans = 0;
for(ll i = 1; i <= n; i ++){
ll a;
std::cin >> a;
ans = std::max(ans,a);
op[a] ++;
}
if(k == 0){
ll res = 0;
for(ll i = 0; i <= ans; i ++){
if(op[i]) res ++;
}
std::cout << res << "\n";
return 0;
}
for(ll i = 0; i <= ans; i ++){
if(op[i] < op[i + k]) op[i + k] -= op[i];
else op[i + k] = 0;
}
ll res = 0;
for(ll i = 0; i <= ans; i ++) res += op[i];
std::cout << res << "\n";
return 0;
}