fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int getSum(int arr[],int n){
  4. unordered_map<int,int>m;
  5. int sum=0;
  6. for(int i=0;i<n;i++){
  7. m[arr[i]]++;
  8. }
  9. for(auto itr=m.begin();itr!=m.end();itr++){
  10. if(itr->first<itr->second){
  11. sum+=itr->second;
  12. }
  13. }
  14. return sum;
  15. }
  16.  
  17. int main() {
  18. // your code goes here
  19. int n;
  20. cin>>n;
  21. int arr[n];
  22. for(int i=0;i<n;i++){
  23. cin>>arr[i];
  24. }
  25. cout<<getSum(arr,n);
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5308KB
stdin
6
2 1 1 2 1 6
stdout
3