prithivMLmods/Coder-Stat huggingface dataset:
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int num, a, thr, cnt;

  cin >> num >> thr;
  cnt = 0;

  map<int, int> M{};
  for (int i = 0; i < num; i++) {
    cin >> a;
    M[a] = M[a] + 1;
  }

  vector<int> v;

  for (map<int, int>::iterator it = M.begin(); it != M.end(); it++) {
    v.push_back(it->second);
  }

  sort(v.begin(), v.end());

  for (int j = 0; j < v.size() - thr; j++) {
    cnt += v[j];
  }

  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int num, a, thr, cnt;

  cin >> num >> thr;
  cnt = 0;

  map<int, int> M{};
  for (int i = 0; i < num; i++) {
    cin >> a;
    M[a] = M[a] + 1;
  }

  vector<int> v;

  for (map<int, int>::iterator it = M.begin(); it != M.end(); it++) {
    v.push_back(it->second);
  }

  sort(v.begin(), v.end());

  if (v.size() >= thr) {
    for (int j = 0; j < v.size() - thr; j++) {
      cnt += v[j];
    }
  }

  cout << cnt << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge)                                                            \
  cerr << "!"                                                                  \
       << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  map<ll, ll> MP;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    MP[a]++;
  }
  vi num;
  for (auto a : MP) {
    num.pb(a.S);
  }
  ll ans = 0;
  sort(ALL(num));
  for (int i = 0; i < num.size() - k; i++)
    ans += num[i];
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge)                                                            \
  cerr << "!"                                                                  \
       << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  map<ll, ll> MP;
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    MP[a]++;
  }
  vi num;
  for (auto a : MP) {
    num.pb(a.S);
  }
  ll ans = 0;
  sort(ALL(num));
  for (int i = 0; i < max(0LL, (ll)num.size() - k); i++)
    ans += num[i];
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
int main() {
  int N, K;
  std::cin >> N >> K;
  std::map<int, int> baket;
  for (int i = 0; i < N; i++) {
    int n;
    std::cin >> n;
    if (baket.count(n))
      baket[n]++;
    else
      baket[n] = 1;
  }
  std::vector<int> cnt;
  for (auto &b : baket)
    cnt.push_back(b.second);
  std::sort(cnt.begin(), cnt.end());
  int sum = 0;
  for (int i = 0; i < cnt.size() - K; i++)
    sum += cnt[i];
  std::cout << sum << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
int main() {
  int N, K;
  std::cin >> N >> K;
  std::map<int, int> baket;
  for (int i = 0; i < N; i++) {
    int n;
    std::cin >> n;
    if (baket.count(n))
      baket[n]++;
    else
      baket[n] = 1;
  }
  std::vector<int> cnt;
  for (auto &b : baket)
    cnt.push_back(b.second);
  std::sort(cnt.begin(), cnt.end());
  int sum = 0;
  int M = static_cast<int>(cnt.size()) - K;
  if (M < 0)
    M = 0;
  for (int i = 0; i < M; i++)
    sum += cnt[i];
  std::cout << sum << std::endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }
  vector<int> B;
  for (auto p : mp) {
    B.push_back(p.second);
  }
  // cout << "Yes"<<endl;

  sort(B.begin(), B.end());
  int sum = 0;
  int f = B.size();
  // cout << B.size() << "  " << K << endl;
  if ((B.size() - K) <= 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < B.size() - K; i++) {
      sum += B[i];
    }
    cout << sum << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    mp[A[i]]++;
  }
  vector<int> B;
  for (auto p : mp) {
    B.push_back(p.second);
  }
  // cout << "Yes"<<endl;

  sort(B.begin(), B.end());
  int sum = 0;
  int f = B.size();
  // cout << B.size() << "  " << K << endl;
  if (((int)B.size() - K) <= 0) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < B.size() - K; i++) {
      sum += B[i];
    }
    cout << sum << endl;
  }
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  rep(i, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  vector<int> v;
  for (auto p : m)
    v.pb(p.second);
  int ans = 0;
  sort(all(v));
  rep(i, v.size() - k) ans += v[i];
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define tmax(a, b, c) max(a, max(b, c))
#define tmin(a, b, c) min(a, min(b, c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  rep(i, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  vector<int> v;
  for (auto p : m)
    v.pb(p.second);
  int ans = 0;
  sort(all(v));
  if (v.size() > k)
    rep(i, v.size() - k) ans += v[i];
  cout << ans << endl;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a[200001] = {}, cnt[200000] = {}, b = 0, ans = 0, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  for (int i = 0; i < n - 1; i++) {
    b++;
    if (a[i] != a[i + 1]) {
      cnt[j] = b;
      b = 0;
      j++;
    }
  }
  cnt[j] = b + 1;
  j++;
  sort(cnt, cnt + j);
  b = j;
  while (1) {
    if (b <= k)
      break;
    for (int i = 0; i < j; i++)
      if (cnt[i] != 0) {
        ans += cnt[i];
        cnt[i] = 0;
        b--;
        break;
      }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, a[200001] = {}, cnt[200000] = {}, b = 0, ans = 0, j = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  for (int i = 0; i < n - 1; i++) {
    b++;
    if (a[i] != a[i + 1]) {
      cnt[j] = b;
      b = 0;
      j++;
    }
  }
  cnt[j] = b + 1;
  j++;
  sort(cnt, cnt + j);
  b = j;
  if (b > k) {
    b -= k;
    for (int i = 0; i < b; i++)
      ans += cnt[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>

using namespace std;

map<int, int> mp;

int a[20005];
bool f[20005];
int res[20005];

int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < k; i++) {
    cin >> a[i];
    f[a[i]] = 1;
    mp[a[i]]++;
  }

  int num = 0;
  for (int i = 0; i < k; i++) {
    if (f[a[i]]) {
      res[num++] = mp[a[i]];
      f[a[i]] = false;
    }
  }

  sort(res, res + num);
  int x = num - n;
  int ans = 0;
  for (int i = 0; i < x; i++) {
    ans += res[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>

using namespace std;

map<int, int> mp;

int a[200005];
bool f[200005];
int res[200005];

int main() {
  int k, n;
  cin >> k >> n;
  for (int i = 0; i < k; i++) {
    cin >> a[i];
    f[a[i]] = 1;
    mp[a[i]]++;
  }

  int num = 0;
  for (int i = 0; i < k; i++) {
    if (f[a[i]]) {
      res[num++] = mp[a[i]];
      f[a[i]] = false;
    }
  }

  sort(res, res + num);
  int x = num - n;
  int ans = 0;
  for (int i = 0; i < x; i++) {
    ans += res[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
const ll LINF = 0x1fffffffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
#define VAR(type, ...)                                                         \
  type __VA_ARGS__;                                                            \
  in(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
  vector<type> name(size);                                                     \
  each(x, name) in(x)
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define each(x, v) for (auto &x : (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl
void in() {}
template <class T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void solve();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}

void solve() {
  VAR(int, N, K);
  VEC(int, A, N);
  map<int, int> m;
  each(x, A) { m[x]++; }
  vi v;
  each(x, m) { v.push_back(x.second); }
  sort(all(v), greater<>());
  print(accumulate(v.begin() + K, v.end(), 0));
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
const ll LINF = 0x1fffffffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
#define VAR(type, ...)                                                         \
  type __VA_ARGS__;                                                            \
  in(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
  vector<type> name(size);                                                     \
  each(x, name) in(x)
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int i = (a - 1); i >= (b); --i)
#define each(x, v) for (auto &x : (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl
void in() {}
template <class T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void solve();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}

void solve() {
  VAR(int, N, K);
  VEC(int, A, N);
  map<int, int> m;
  each(x, A) { m[x]++; }
  vi v;
  each(x, m) { v.push_back(x.second); }
  sort(all(v), greater<>());
  int ans = 0;
  rep(i, K, (int)v.size()) { ans += v[i]; }
  print(ans);
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_eq(i, x, n) for (int i = x; i <= (int)(n); i++)
using namespace std;

using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, 0, N) { cin >> A[i]; }
  vector<int> c(5 + 1);
  rep(i, 0, N) { c[A[i]]++; }
  sort(c.rbegin(), c.rend());
  int ans = N;
  rep(i, 0, K) { ans -= c[i]; }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep_eq(i, x, n) for (int i = x; i <= (int)(n); i++)
using namespace std;

using ll = long long;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, 0, N) { cin >> A[i]; }
  vector<int> c(N + 1);
  rep(i, 0, N) { c[A[i]]++; }
  sort(c.rbegin(), c.rend());
  int ans = N;
  rep(i, 0, K) { ans -= c[i]; }
  cout << ans << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int n, m;
  int i, j, k, l;
  string s;
  cin >> n >> k;
  int a[n], b[n + 1];
  vector<int> vec;

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n + 1; i++) {
    b[i] = 0;
  }

  for (i = 0; i < n; i++) {
    b[a[i]]++;
  }
  for (i = 0; i < n + 1; i++) {
    if (b[i] > 0) {
      vec.push_back(b[i]);
    }
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  for (i = 0; i < vec.size() - k; i++) {
    ans += vec[i];
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int n, m;
  int i, j, k, l;
  string s;
  cin >> n >> k;
  int a[n], b[n + 1];
  vector<int> vec;

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n + 1; i++) {
    b[i] = 0;
  }

  for (i = 0; i < n; i++) {
    b[a[i]]++;
  }
  for (i = 0; i < n + 1; i++) {
    if (b[i] > 0) {
      vec.push_back(b[i]);
    }
  }
  sort(vec.begin(), vec.end());
  int ans = 0;
  if (vec.size() < k) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 0; i < vec.size() - k; i++) {
    ans += vec[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

int N, K;
map<int, int> bmap;

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    bmap[a] = bmap.find(a) != bmap.end() ? bmap[a] + 1 : 1;
  }

  if (bmap.size() <= K) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> v;
  for (auto kv : bmap)
    v.push_back(kv.second);
  sort(v.begin(), v.end());

  int ans = 0;
  while (v.size() > K) {
    ans += v.front();
    v.erase(v.begin());
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;

int N, K;
map<int, int> bmap;

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    bmap[a] = bmap.find(a) != bmap.end() ? bmap[a] + 1 : 1;
  }

  if (bmap.size() <= K) {
    cout << 0 << endl;
    return 0;
  }

  vector<int> v;
  for (auto kv : bmap)
    v.push_back(kv.second);
  sort(v.begin(), v.end());

  int ans = 0;
  for (int i = 0; i < v.size() - K; ++i) {
    ans += v[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<int, int> check;
int cou[200] = {0}, pos = 0, pos1 = 0;
int main() {
  int n, k, tmp, ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (check.count(tmp) == 0) {
      check[tmp] = pos;
      cou[pos++]++;
    } else
      cou[check[tmp]]++;
  }
  sort(cou, cou + pos);
  for (int i = 0; i < pos - k; i++) {
    ans += cou[pos1++];
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<int, int> check;
int cou[200001] = {0}, pos = 0, pos1 = 0;
int main() {
  int n, k, tmp, ans = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (check.count(tmp) == 0) {
      check[tmp] = pos;
      cou[pos++]++;
    } else
      cou[check[tmp]]++;
  }
  sort(cou, cou + pos);
  for (int i = 0; i < pos - k; i++) {
    ans += cou[pos1++];
  }
  printf("%d", ans);
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int a[20010];

int main() {
  int l = 100000, r = 0;
  int n, k;
  cin >> n >> k;
  int d;
  for (int i = 1; i <= n; i++) {
    cin >> d;
    a[d]++;
    l = min(l, d);
    r = max(r, d);
  }

  if (r - l + 1 <= k) {
    cout << 0;
    return 0;
  }
  sort(a + l, a + r + 1);

  int ans = 0;
  while (r - l + 1 > k) {
    ans += a[l];
    l++;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int a[2000010];

int main() {
  int l = 100000, r = 0;
  int n, k;
  cin >> n >> k;
  int d;
  for (int i = 1; i <= n; i++) {
    cin >> d;
    a[d]++;
    l = min(l, d);
    r = max(r, d);
  }

  if (r - l + 1 <= k) {
    cout << 0;
    return 0;
  }
  sort(a + l, a + r + 1);

  int ans = 0;
  while (r - l + 1 > k) {
    ans += a[l];
    l++;
  }
  cout << ans;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>())   // descend
// sort(a, a+N)                    //  ascend

/*
void comb(vector<vector <ll> > &v) {
        ll mod=1000000007;
        rep (i,0,v.size()) {
                v[i][0] = 1;
                v[i][i] = 1;
        }
        rep (k,1,v.size()) {
                rep (j,1,k) {
                        v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
                }
        }
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
  ll n, k;
  cin >> n >> k;
  ll a[220000];
  rep(i, 0, n) cin >> a[i];
  ll b[220000] = {0};
  rep(i, 0, n) {
    rep(j, 1, n + 1) {
      if (a[i] == j)
        b[j]++;
    }
  }
  b[0] == 454507213;
  sort(b, b + n + 1);
  ll cnt = 0;
  ll start = 0;
  ll ans = 0;
  rep(i, 0, n + 1) if (b[i] != 0) cnt++;
  rep(i, 0, n + 1) if (b[i] != 0) {
    start = i;
    break;
  }
  if (cnt - k > 0)
    rep(i, start, start + cnt - k) ans += b[i];
  if (cnt - k <= 0)
    cout << "0";
  else
    cout << ans;
  // rep(i,0,n+1)cout<<b[i]<<endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>())   // descend
// sort(a, a+N)                    //  ascend

/*
void comb(vector<vector <ll> > &v) {
        ll mod=1000000007;
        rep (i,0,v.size()) {
                v[i][0] = 1;
                v[i][i] = 1;
        }
        rep (k,1,v.size()) {
                rep (j,1,k) {
                        v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
                }
        }
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
  ll n, k;
  cin >> n >> k;
  ll a[220000];
  rep(i, 0, n) cin >> a[i];
  ll b[220000] = {0};
  rep(i, 0, n) b[a[i]]++;
  b[0] == 454507213;
  sort(b, b + n + 1);
  ll cnt = 0;
  ll start = 0;
  ll ans = 0;
  rep(i, 0, n + 1) if (b[i] != 0) cnt++;
  rep(i, 0, n + 1) if (b[i] != 0) {
    start = i;
    break;
  }
  if (cnt - k > 0)
    rep(i, start, start + cnt - k) ans += b[i];
  if (cnt - k <= 0)
    cout << "0";
  else
    cout << ans;
  // rep(i,0,n+1)cout<<b[i]<<endl;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define full(c) c.begin(), c.end()
#define vector2d(name, type, h, w, init)                                       \
  vector<vector<type>> name(h, vector<type>(w, init))
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  int i, k, n, cnt = 0;
  cin >> n >> k;
  map<int, int> acnt;
  multiset<int> avar;
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    acnt[a]++;
  }
  for (const auto k : acnt) {
    avar.insert(k.second);
  }
  i = 0;
  for (set<int>::iterator it = avar.begin(); i < avar.size() - k; i++, it++) {
    cnt += *it;
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define full(c) c.begin(), c.end()
#define vector2d(name, type, h, w, init)                                       \
  vector<vector<type>> name(h, vector<type>(w, init))
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  int i, k, n, cnt = 0;
  cin >> n >> k;
  map<int, int> acnt;
  multiset<int> avar;
  for (i = 0; i < n; i++) {
    int a;
    cin >> a;
    acnt[a]++;
  }
  for (const auto k : acnt) {
    avar.insert(k.second);
  }
  i = 0;
  for (set<int>::iterator it = avar.begin(); i < (int)avar.size() - k;
       i++, it++) {
    cnt += *it;
  }
  cout << cnt << endl;
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> data(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  vector<int> num(N, 0);
  for (int i = 0; i < N; i++) {
    num.at(data.at(i) - 1)++;
  }
  sort(num.begin(), num.end());
  int M = 0;
  for (int i = 0; i < N; i++) {
    if (num.at(i) > 0)
      M++;
  }
  int L = M - K;
  int count;
  for (int i = M; i < M + L; i++) {
    count += num.at(i);
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> data(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  vector<int> num(N, 0);
  for (int i = 0; i < N; i++) {
    num.at(data.at(i) - 1)++;
  }
  sort(num.begin(), num.end());
  int M = 0;
  for (int i = 0; i < N; i++) {
    if (num.at(i) > 0)
      M++;
  }
  int L = M - K;
  int count;
  for (int i = N - M; i < N - M + L; i++) {
    count += num.at(i);
  }
  cout << count << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
/*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); i++)

int Len(int n) {
  int s = 0;
  while (n != 0)
    s++, n /= 10;
  return s;
}

int Sint(int n) {
  int m = 0, s = 0, a = n;
  while (a != 0)
    s++, a /= 10;
  for (int i = s - 1; i >= 0; i--)
    m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
  return m;
}

int Svec(vector<int> v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++)
    n += v[i];
  return n;
}

int GCD(int a, int b) {
  int r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return b;
}

int LCM(int a, int b) {
  int c = a, d = b, r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return c / b * d;
}

int Factorial(int n) {
  int m = 1;
  while (n >= 1)
    m *= n, n--;
  return m;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n), w;
  set<int> st;
  map<int, int> mp;
  rep(i, n) {
    cin >> v[i];
    st.insert(v[i]);
    mp[v[i]]++;
  }
  for (auto c : mp) {
    w.push_back(c.second);
  }
  sort(w.begin(), w.end());
  int ans = 0;
  if (st.size() <= k) {
    cout << 0 << endl;
    return 0;
  } else {
    rep(i, k - st.size()) ans += w[i];
  }

  cout << ans << endl;
}

Fixed submission:
/*Function Template*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (n); i++)

int Len(int n) {
  int s = 0;
  while (n != 0)
    s++, n /= 10;
  return s;
}

int Sint(int n) {
  int m = 0, s = 0, a = n;
  while (a != 0)
    s++, a /= 10;
  for (int i = s - 1; i >= 0; i--)
    m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
  return m;
}

int Svec(vector<int> v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++)
    n += v[i];
  return n;
}

int GCD(int a, int b) {
  int r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return b;
}

int LCM(int a, int b) {
  int c = a, d = b, r, tmp;
  /*自然数 a > b を確認・入替*/
  if (a < b) {
    tmp = a, a = b, b = tmp;
  }
  /*ユークリッドの互除法*/
  r = a % b;
  while (r != 0) {
    a = b, b = r, r = a % b;
  }
  return c / b * d;
}

int Factorial(int n) {
  int m = 1;
  while (n >= 1)
    m *= n, n--;
  return m;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n), w;
  set<int> st;
  map<int, int> mp;
  rep(i, n) {
    cin >> v[i];
    st.insert(v[i]);
    mp[v[i]]++;
  }
  for (auto c : mp) {
    w.push_back(c.second);
  }
  sort(w.begin(), w.end());
  int ans = 0;
  if (st.size() <= k) {
    cout << 0 << endl;
    return 0;
  } else {
    rep(i, st.size() - k) ans += w[i];
  }

  cout << ans << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT() {}
template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) {
  cin >> head;
  CINT(move(tail)...);
}
#define CIN(...)                                                               \
  int __VA_ARGS__;                                                             \
  CINT(__VA_ARGS__)
#define LCIN(...)                                                              \
  ll __VA_ARGS__;                                                              \
  CINT(__VA_ARGS__)
#define SCIN(...)                                                              \
  string __VA_ARGS__;                                                          \
  CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int cnt[MAX_N];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  CIN(N, K);
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
    cnt[a[i]]++;
  }

  sort(cnt, cnt + MAX_N, [](int x, int y) { return x > y; });

  int ans = 0;
  FOR(i, K, N)
  ans += cnt[i];

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define EACH(i, a) for (auto &i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT() {}
template <class Head, class... Tail> void CINT(Head &&head, Tail &&...tail) {
  cin >> head;
  CINT(move(tail)...);
}
#define CIN(...)                                                               \
  int __VA_ARGS__;                                                             \
  CINT(__VA_ARGS__)
#define LCIN(...)                                                              \
  ll __VA_ARGS__;                                                              \
  CINT(__VA_ARGS__)
#define SCIN(...)                                                              \
  string __VA_ARGS__;                                                          \
  CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e6 + 1;

int cnt[MAX_N];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  CIN(N, K);
  vector<int> a(N);
  REP(i, N) {
    cin >> a[i];
    cnt[a[i]]++;
  }

  sort(cnt, cnt + MAX_N, [](int x, int y) { return x > y; });

  int ans = 0;
  FOR(i, K, N)
  ans += cnt[i];

  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int N, t, K;
map<int, int> m;
int ans;

bool compare(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }

vector<pair<int, int>> f(map<int, int> &target) {
  vector<pair<int, int>> vt;
  vector<pair<int, int>>::iterator it_vt;
  map<int, int>::iterator it_map;

  for (it_map = target.begin(); it_map != target.end(); it_map++) {
    vt.push_back(make_pair(it_map->second, it_map->first));
  }
  sort(vt.rbegin(), vt.rend(), compare);

  target.clear();

  return vt;
}

int main() {
  ios::sync_with_stdio(false);

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> t;
    auto ret = m.insert({t, 1});
    if (!ret.second) { // duplicate
      m.find(t)->second++;
    }
  }

  vector<pair<int, int>> s = f(m);
  for (int i = 0; i < s.size() - K; i++) {
    // out << s[i].first << ":" << s[i].second << endl;
    ans += s[i].first;
  }
  cout << ans << endl;

  /*

  for(std::map<int, int>::const_iterator it = m.begin(); it != m.end(); it++)
  {
      int key = it->first;
      int value = it->second;
      cout << key << ":" << value << endl;
  }
  cout << ans << '\n';
  */
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int N, t, K;
map<int, int> m;
int ans;

bool compare(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }

vector<pair<int, int>> f(map<int, int> &target) {
  vector<pair<int, int>> vt;
  vector<pair<int, int>>::iterator it_vt;
  map<int, int>::iterator it_map;

  for (it_map = target.begin(); it_map != target.end(); it_map++) {
    vt.push_back(make_pair(it_map->second, it_map->first));
  }
  sort(vt.rbegin(), vt.rend(), compare);

  target.clear();

  return vt;
}

int main() {
  ios::sync_with_stdio(false);

  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> t;
    auto ret = m.insert({t, 1});
    if (!ret.second) { // duplicate
      m.find(t)->second++;
    }
  }

  vector<pair<int, int>> s = f(m);

  for (int i = 0; i < s.size() - K && (int)s.size() - K >= 0; i++) {
    // out << s[i].first << ":" << s[i].second << endl;
    ans += s[i].first;
  }
  cout << ans << endl;

  /*

  for(std::map<int, int>::const_iterator it = m.begin(); it != m.end(); it++)
  {
      int key = it->first;
      int value = it->second;
      cout << key << ":" << value << endl;
  }
  cout << ans << '\n';
  */
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == i) {
        b[i - 1]++;
      }
    }
  }
  sort(b.begin(), b.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += b[i];
  }
  cout << n - sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  sort(b.begin(), b.end(), greater<int>());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += b[i];
  }
  cout << n - sum << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int i, j;
  int n, k;
  vector<int> v(205);
  vector<int> v2(205);
  map<int, int> mp;
  map<int, int>::iterator it;
  int nn;
  int cnt = 0;

  cin >> n >> k;

  for (i = 0; i < n; i++) {
    cin >> v[i];
    if (mp.count(v[i]) == 0) {
      mp.insert(pair<int, int>(v[i], 1));
    } else {
      mp[v[i]]++;
    }
  }

  if (mp.size() <= k) {
    cout << 0 << endl;
    goto label;
  }

  i = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    v2[i] = (*it).second;
    i++;
  }

  sort(v2.begin(), v2.end());

  i = std::count(v2.begin(), v2.end(), 0);
  nn = i;

  for (i; i < nn + mp.size() - k; i++) {
    cnt += v2[i];
  }

  cout << cnt << endl;

label:

  getchar();
  getchar();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int i, j;
  int n, k;
  vector<int> v(200000);
  vector<int> v2(200000);
  map<int, int> mp;
  map<int, int>::iterator it;
  int nn;
  int cnt = 0;

  cin >> n >> k;

  for (i = 0; i < n; i++) {
    cin >> v[i];
    if (mp.count(v[i]) == 0) {
      mp.insert(pair<int, int>(v[i], 1));
    } else {
      mp[v[i]]++;
    }
  }

  if (mp.size() <= k) {
    cout << 0 << endl;
    goto label;
  }

  i = 0;
  for (it = mp.begin(); it != mp.end(); it++) {
    v2[i] = (*it).second;
    i++;
  }

  sort(v2.begin(), v2.end());

  i = std::count(v2.begin(), v2.end(), 0);
  nn = i;

  for (i; i < nn + mp.size() - k; i++) {
    cnt += v2[i];
  }

  cout << cnt << endl;

label:

  getchar();
  getchar();
  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), species;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int tmp = A[0], cnt = 1;
  for (int i = 1; i < N; i++) {
    if (tmp == A[i])
      cnt++;
    else {
      species.push_back(cnt);
      cnt = 1;
      tmp = A[i];
    }
  }
  species.push_back(cnt);
  sort(species.begin(), species.end());
  int ans = 0;
  for (int i = 0; i < species.size() - K; i++) {
    ans += species[i];
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), species;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int tmp = A[0], cnt = 1;
  for (int i = 1; i < N; i++) {
    if (tmp == A[i])
      cnt++;
    else {
      species.push_back(cnt);
      cnt = 1;
      tmp = A[i];
    }
  }
  species.push_back(cnt);
  sort(species.begin(), species.end());
  int ans = 0;
  for (int i = 0; i < max(0, (int)species.size() - K); i++) {
    ans += species[i];
  }
  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long int Int;
Int N, K;
map<Int, Int> A;
vector<Int> S;

int Calc() {
  sort(S.begin(), S.end(), greater<Int>());

  Int sum = 0;
  for (Int i = 0; i < K; i++) {
    sum += S[i];
  }

  return N - sum;
}

int main(void) {
  cin >> N >> K;

  for (Int i = 0; i < N; i++) {
    Int temp;
    cin >> temp;

    A[temp]++;
  }

  for (map<Int, Int>::iterator it = A.begin(); it != A.end(); it++) {
    S.push_back(it->second);
  }

  cout << Calc() << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long int Int;
Int N, K;
map<Int, Int> A;
vector<Int> S;

int Calc() {
  sort(S.begin(), S.end(), greater<Int>());

  Int sum = 0;
  for (Int i = 0; i < K && i < S.size(); i++) {
    sum += S[i];
  }

  return N - sum;
}

int main(void) {
  cin >> N >> K;

  for (Int i = 0; i < N; i++) {
    Int temp;
    cin >> temp;

    A[temp]++;
  }

  for (map<Int, Int>::iterator it = A.begin(); it != A.end(); it++) {
    S.push_back(it->second);
  }

  cout << Calc() << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, K;
map<int, int> mp;

int main(void) {

  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    ++mp[a];
  }

  vector<P> v;
  for (auto m : mp)
    v.push_back(make_pair(m.second, m.first));
  sort(v.begin(), v.end(), greater<P>());

  int cnt = 0;
  for (int i = 0; i < K; ++i)
    cnt += v[i].first;
  if (N - cnt <= 0)
    printf("0\n");
  else
    printf("%d\n", N - cnt);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, K;
map<int, int> mp;

int main(void) {

  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    ++mp[a];
  }

  vector<P> v;
  for (auto m : mp)
    v.push_back(make_pair(m.second, m.first));
  sort(v.begin(), v.end(), greater<P>());

  int cnt = 0;
  for (int i = 0; i < K && i < v.size(); ++i)
    cnt += v[i].first;
  if (N - cnt <= 0)
    printf("0\n");
  else
    printf("%d\n", N - cnt);

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int count[20020];
  for (int i = 0; i < A.size(); i++) {
    count[A.at(i)]++;
  }
  sort(count, count + A.size());
  reverse(count, count + A.size());

  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += count[i];
  }
  cout << N - sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int count[200200] = {0};
  for (int i = 0; i < A.size(); i++) {
    count[A.at(i)]++;
  }
  sort(count, count + A.size());
  reverse(count, count + A.size());

  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += count[i];
  }
  cout << N - sum << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int *A;

int main(void) {
  int N, K;
  cin >> N >> K;

  A = new int[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  sort(A, A + N);

  int kind = 0, tmp = A[0];
  int cnt = 1;
  int *num = new int[K];
  for (int i = 1; i < N; ++i) {
    if (A[i] > tmp) {
      num[kind] = cnt;
      ++kind;
      cnt = 0;
      tmp = A[i];
    }
    ++cnt;
  }
  num[kind] = cnt;
  ++kind;

  sort(num, num + kind);

  int sum = 0;
  for (int i = 0; i < kind - K; ++i) {
    sum += num[i];
  }

  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int *A;

int main(void) {
  int N, K;
  cin >> N >> K;

  A = new int[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  sort(A, A + N);

  int kind = 0, tmp = A[0];
  int cnt = 1;
  int *num = new int[N];
  for (int i = 1; i < N; ++i) {
    if (A[i] > tmp) {
      num[kind] = cnt;
      ++kind;
      cnt = 0;
      tmp = A[i];
    }
    ++cnt;
  }
  num[kind] = cnt;
  ++kind;

  sort(num, num + kind);

  int sum = 0;
  for (int i = 0; i < kind - K; ++i) {
    sum += num[i];
  }

  cout << sum << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {

  int N, K;
  cin >> N >> K;
  map<int, int> kinds;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    kinds[a]++;
  }
  int ans = 0;
  int n_of_kinds_to_change = (int)kinds.size() - K;
  if (n_of_kinds_to_change <= 0) {
    cout << ans << endl;
    return 0;
  } else {
    while (n_of_kinds_to_change) {
      int min_n_balls = N;
      int num;
      for (auto itr : kinds) {
        if (min_n_balls > itr.second) {
          num = itr.first;
          min_n_balls = itr.second;
        }
      }
      ans += min_n_balls;
      n_of_kinds_to_change--;
      kinds.erase(num);
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main(int argc, const char *argv[]) {

  int N, K;
  cin >> N >> K;
  map<int, int> kinds;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    kinds[a]++;
  }
  int ans = 0;
  int n_of_kinds_to_change = (int)kinds.size() - K;
  if (n_of_kinds_to_change <= 0) {
    cout << ans << endl;
    return 0;
  } else {
    vector<int> v;
    for (auto itr : kinds) {
      v.push_back(itr.second);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n_of_kinds_to_change; i++) {
      ans += v.at(i);
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main() {
  int n, k, a[200000];
  vector<int> num;
  map<int, int> mp;
  cin >> n >> k;
  num.push_back(100000000);
  REP(i, n) {
    cin >> a[i];
    if (mp[a[i]] == 0) {
      mp[a[i]] = num.size();
      num.push_back(1);
    } else {
      num[mp[a[i]]]++;
    }
  }

  SORT(num);

  int ans = 0;
  for (int i = 0; i < num.size() - k; i++) {
    ans += num[i];
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main() {
  int n, k, a[200000];
  vector<int> num;
  map<int, int> mp;
  cin >> n >> k;
  num.push_back(100000000);
  REP(i, n) {
    cin >> a[i];
    if (mp[a[i]] == 0) {
      mp[a[i]] = num.size();
      num.push_back(1);
    } else {
      num[mp[a[i]]]++;
    }
  }

  SORT(num);

  int ans = 0;
  for (int i = 0; i < (int)num.size() - k - 1; i++) {
    ans += num[i];
  }

  cout << ans << endl;

  return 0;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

int cnt[20010];

int main() {
  int n, k;
  cin >> n >> k;

  rep(i, n) {
    int a;
    cin >> a;
    cnt[a - 1]++;
  }
  sort(cnt, cnt + n);
  int ans = 0;
  rep(i, n - k) { ans += cnt[i]; }

  cout << ans << endl;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = 1LL << 60;

int cnt[200010];

int main() {
  int n, k;
  cin >> n >> k;

  rep(i, n) {
    int a;
    cin >> a;
    cnt[a - 1]++;
  }
  sort(cnt, cnt + n);
  int ans = 0;
  rep(i, n - k) { ans += cnt[i]; }

  cout << ans << endl;
}
Problem p03495 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int type = 0;
  vector<int> num(20001, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (num[a] == 0)
      type++;
    num[a]++;
  }
  if (type <= k) {
    cout << 0 << endl;
    return 0;
  }
  type -= k;
  sort(num.begin(), num.end());
  long long ans = 0;
  int i = 0;
  while (type != 0) {
    if (num[i] == 0) {
      i++;
      continue;
    }
    type--;
    ans += num[i];
    i++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int type = 0;
  vector<int> num(200001, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (num[a] == 0)
      type++;
    num[a]++;
  }
  if (type <= k) {
    cout << 0 << endl;
    return 0;
  }
  type -= k;
  sort(num.begin(), num.end());
  long long ans = 0;
  int i = 0;
  while (type != 0) {
    if (num[i] == 0) {
      i++;
      continue;
    }
    type--;
    ans += num[i];
    i++;
  }
  cout << ans << endl;
}