fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8. int n,steps=0;
  9. cin>>n;
  10. vector<int>pile(n+1,0);
  11. vector<pair<int,int>>arr;
  12. map<int,int>m;
  13. for(int i=0;i<n;i++){
  14. cin>>pile[i];
  15. m[pile[i]]++;
  16. }
  17. for(auto x: m){
  18. arr.push_back({x.first,x.second});
  19. }
  20. int size=arr.size();
  21. for(int i=size-1;i>0;i--){
  22. arr[i-1].second+=arr[i].second;
  23. steps+=arr[i].second;
  24. arr[i].second=0;
  25. }
  26. cout<<steps;
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
3 1 2 2 3
stdout
6