fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, k;
  6. cin >> n >> k;
  7.  
  8. vector<int> values(n);
  9. for(int i = 0; i < n; i++){
  10. cin >> values[i];
  11. }
  12.  
  13. map<int,int> mp;
  14. for(auto i: values){
  15. mp[i]++;
  16. }
  17.  
  18. // convert into vector<pair<int,int>>
  19. vector<pair<int,int>> vp;
  20. for(auto u: mp){
  21. vp.push_back({u.first, u.second});
  22. }
  23.  
  24. int noOfOperations = 0;
  25.  
  26. for(int i = vp.size() - 1; i >= 1; i--){
  27. vp[i-1].second += vp[i].second;
  28. noOfOperations += vp[i].second;
  29. vp[i].second = 0;
  30. }
  31.  
  32. cout<<noOfOperations<<endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5320KB
stdin
5
4 5 5 2 4
stdout
9