pastebin

Paste Search Dynamic
Recent pastes
goodSequence
  1. #include <iostream>
  2. #include <unordered_map>
  3. using namespace std;
  4.  
  5. int goodSequence(int a[], int n) {
  6.     unordered_map<int, int> count;
  7.     int remove = 0;
  8.     for (int i = 0; i < n; i++) {
  9.         count[a[i]]++;
  10.     }
  11.     for (auto x : count) {
  12.         remove += abs(x.first - x.second);
  13.     }
  14.     return remove;
  15. }
  16.  
  17. int main() {
  18.     int n;
  19.     cin >> n;
  20.     int a[n];
  21.     for (int i = 0; i < n; i++) {
  22.         cin >> a[i];
  23.     }
  24.     cout << goodSequence(a, n) << endl;
  25.     return 0;
  26. }
Parsed in 0.011 seconds