题解:P15138 [SWERC 2025] Dungeon Equilibrium
P15138 [SWERC 2025] Dungeon Equilibrium
solution
简单题。
我们开一个数组记录
::::info[第
::::info[第
::::info[第
做完了qwq。
AC code
#include <bits/stdc++.h>
#define debug(a) cerr << (#a) << " = " << (a) << endl;
#define int long long
#define maxn 100010
#define endl '\n'
using namespace std;
int n;
int max_a;
int a[maxn], cnt[maxn];
int solve() {
int tot = 0;
for (int i = 0; i <= max_a; i++) {
if (cnt[i] < i) {
tot += cnt[i];
}
else if (cnt[i] > i) {
tot += (cnt[i] - i);
}
}
return tot;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t; t = 1;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
max_a = max(max_a, a[i]), cnt[a[i]]++;
}
cout << solve() << endl;
}
return 0;
}