#P15138. [SWERC 2025] Dungeon Equilibrium

[SWERC 2025] Dungeon Equilibrium

题目描述

You are developing a new RPG game where each monster species has a peculiar rule about how many times it should appear on a level.

A level is represented by an array of integers a1,a2,,ana_1, a_2, \dots, a_n, where each integer represents the type of a monster.

A level is considered balanced if, for every monster type xx that appears, there are exactly xx monsters of that type. For example, a balanced level might have three monsters of type 3, five of type 5, and so on. An empty level (no monsters at all) is also considered balanced.

Unfortunately, your current level design is not necessarily balanced. You can delete some monsters (i.e., remove elements from the array) to make it balanced.

Given the array a1,a2,,ana_1, a_2, \dots, a_n, find the minimum number of monsters you need to remove to make the level balanced.

输入格式

The first line contains an integer nn (1n10001 \le n \le 1000) — the current number of monsters in the level.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ain0 \le a_i \le n) — the monster types.

输出格式

Output a single line containing an integer: the minimum number of monsters you should remove from the level to make it balanced.

5
1 1 2 2 3
2
10
1 2 3 2 4 4 4 4 5 2
3

提示

Explanation of sample 1.

In the first example, you can remove one monster of type 1 and one of type 3. The level then becomes [1,2,2][1, 2, 2], which is balanced (it has one monster of type 1 and two of type 2). You cannot make the level balanced with fewer than 2 removals, so the answer is 2.

Explanation of sample 2.

In the second example, you can make the level [1,2,4,4,4,4,2][1, 2, 4, 4, 4, 4, 2].