fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int ans(vector<int>&v){
  5. int steps=0;map<int,int>freq;
  6. for(int i=0;i<v.size();i++){
  7. freq[v[i]]++;
  8. }
  9. vector<int>temp;
  10. for(auto x :freq){
  11. temp.push_back(x.first);
  12. }
  13. sort(temp.begin(),temp.end());
  14. for(int j=temp.size()-1;j>0;j--){
  15. if(j!=temp.size()-1){
  16. freq[temp[j]]+=freq[temp[j+1]];
  17. }
  18. steps+=freq[temp[j]];
  19.  
  20. }
  21. return steps;
  22. }
  23. int main(){
  24. int n;cin>>n;
  25. vector<int>v(n);
  26. for(int i=0;i<n;i++)cin>>v[i];
  27. cout<<ans(v);
  28. }
Success #stdin #stdout 0s 5328KB
stdin
3
5 4 1
stdout
3