fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. bool check(vector<int> &arr,int mid){
  8. int n = arr.size();
  9. int i = n-mid;
  10.  
  11. int j=0;
  12.  
  13. while(i<n){
  14. if(arr[j]>=arr[i]){
  15. return false;
  16. }
  17. i++;
  18. j++;
  19. }
  20. return true;
  21.  
  22. }
  23. int main() {
  24. // your code goes here
  25. int n;
  26. vector<int> arr(n);
  27. for(int i=0;i<n;i++){
  28. cin>>arr[i];
  29. }
  30.  
  31. sort(arr.begin(),arr.end());
  32. int low=0;
  33. int high=n-1;
  34. int ans=0;
  35.  
  36. while(low<=high){
  37. cout<<"yes";
  38. int mid = (low+high)/2;
  39.  
  40. if(check(arr,mid)==true){
  41. ans = mid;
  42. low=mid+1;
  43.  
  44. }
  45. else{
  46. high=mid-1;
  47.  
  48. }
  49. }
  50. cout<<ans<<endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 544KB
stdin
7
1 3 5 2 5 3 1
stdout
0