fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone{
  9. public static int sol(int arr[]){
  10. TreeMap<Integer,Integer> mp = new TreeMap<>(Collections.reverseOrder());
  11. for(int i=0;i<arr.length;i++){
  12. mp.put(arr[i],mp.getOrDefault(arr[i],0)+1);
  13. }
  14. int steps = 0;
  15. int next = 0;
  16. mp.pollLastEntry();
  17. for(int i:mp.keySet()){
  18. mp.put(i,mp.get(i)+next);
  19. steps=steps+mp.get(i);
  20. next=mp.get(i);
  21. }
  22. return steps;
  23. }
  24. public static void main (String[] args) throws java.lang.Exception{
  25. Scanner sc = new Scanner(System.in);
  26. int n = sc.nextInt();
  27. int arr[] = new int[n];
  28. for(int i=0;i<n;i++){
  29. arr[i]=sc.nextInt();
  30. }
  31. System.out.println(sol(arr));
  32.  
  33. }
  34. }
Success #stdin #stdout 0.1s 56628KB
stdin
5
4 5 5 2 4
stdout
6