Untitled
unknown
c_cpp
18 days ago
953 B
8
Indexable
#include <bits/stdc++.h> using namespace std; void MO3TAZOLEQ() { #ifdef MOATAZOLEQ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } #define ll long long void solve() { int n; cin >> n; map<int, int> mp, mp2; for (int i = 0, x; i < n; ++i) { cin >> x; mp[x]++; } for (auto [x, freq]: mp) { mp2[freq]++; } int ans = n; for (auto [x, freq]: mp2) { // x => target freq int cur = 0; for (auto [y, freq2]: mp2) { if (y < x) { // erase all freq2 cur += freq2 * y; } else { cur += (y - x) * freq2; } } ans = min(ans, cur); } cout << ans << '\n'; } int main() { MO3TAZOLEQ(); ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
Editor is loading...
Leave a Comment