Guest User

Untitled

a guest
Jul 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.util.*;
  2. public class CPU_SCHEDULING{
  3.  
  4. public static void main(String []args){
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7. int temp = n;
  8. ArrayList<Node> ar = new ArrayList<>();
  9. while(n-->0)
  10. {
  11. Node nd = new Node(sc.nextInt(),sc.nextInt());
  12. ar.add(nd);
  13.  
  14. }
  15.  
  16. Collections.sort(ar,new Sort());
  17.  
  18.  
  19. long sum = 0;
  20. long length = 0;
  21. for(Node x : ar)
  22. {
  23. length = length + x.l;
  24. sum = sum + x.w * ( length);
  25. }
  26.  
  27. System.out.println(sum);
  28. }
  29. }
  30.  
  31.  
  32. class Node{
  33. int w,l;
  34. float dif;
  35. Node(int w,int l)
  36. {
  37. this.w = w;
  38. this.l = l;
  39. dif = (float)w / (float)l;
  40. }
  41.  
  42. public String toString()
  43. {
  44. return this.w+" "+this.l+" "+this.dif;
  45. }
  46.  
  47. }
  48.  
  49. class Sort implements Comparator<Node>
  50. {
  51.  
  52. public int compare(Node a , Node b)
  53. {
  54. if(a.dif - b.dif != 0)
  55. return (int)Math.signum(b.dif - a.dif);
  56. else return (int)Math.signum(b.w - a.w);
  57.  
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment