Advertisement
arsovski

weAreElectric

Oct 22nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2.  
  3. import java.util.*;
  4. public class ElectricalEnergy {
  5.  
  6. public static void main(String[] args){
  7.  
  8. Scanner sc=new Scanner(System.in);
  9. int n=sc.nextInt();
  10. long[] buildings=new long[n];
  11.  
  12. for(int i=0;i<n;i++){
  13. buildings[i]=sc.nextInt();
  14. }
  15.  
  16.  
  17. long[] energyStorage=new long[n];
  18. for(int i=1;i<buildings.length;i++){
  19. long counter=0;
  20. quickSort(buildings,0,i-1);
  21. int j=i-1;
  22. while(j>=0)
  23.  
  24. if(buildings[i] < buildings[j]){
  25. counter++;
  26.  
  27. j--;
  28. }
  29. }
  30. energyStorage[i]=counter;
  31. }
  32.  
  33. long energyNeeded=0;
  34. for(int i=0;i<energyStorage.length;i++)
  35. energyNeeded+=energyStorage[i];
  36.  
  37. System.out.println(energyNeeded);
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement