fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6.  
  7. int n;
  8. cin>>n;
  9. vector<int>arr(n+1,0);
  10. for(int i=1;i<=n;i++){
  11. cin>>arr[i];
  12. }
  13. // store freq of each pile in hashmap
  14. map<int, int> mp;
  15. for(int i=1;i<=n;i++){
  16. mp[arr[i]]++;
  17.  
  18. }
  19.  
  20. vector<pair<int, int>>p;
  21. for(auto u : mp){
  22. p.push_back({u.first, u.second});
  23. }
  24. int step=0;
  25. int size= p.size();
  26.  
  27. for(int i= size-1;i>=1;--i){
  28. p[i-1].second= p[i-1].second+p[i].second;
  29. step= step+p[i].second;
  30. p[i].second=0;
  31. }
  32. cout<<step<<endl;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
5 2 3 1 2
stdout
7