fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include<vector>
  4. #include <bits/stdc++.h>
  5. int main() {
  6. // your code goes here
  7. unordered_map<int,int>mp;
  8. vector<int>arr={1,2,3,3,2,3,2,3,3};
  9. for(int i=0;i<arr.size();i++)
  10. {
  11. mp[arr[i]]++;
  12. }
  13.  
  14. int sum=0;
  15. for(auto x:mp)
  16. {
  17. if(x.second>=x.first)
  18. {
  19. sum+=x.first;
  20. }
  21. }
  22. cout<<sum;
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5284KB
stdin
stdout
6