Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CPU_SCHEDULING{
- public static void main(String []args){
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int temp = n;
- ArrayList<Node> ar = new ArrayList<>();
- while(n-->0)
- {
- Node nd = new Node(sc.nextInt(),sc.nextInt());
- ar.add(nd);
- }
- Collections.sort(ar,new Sort());
- long sum = 0;
- long length = 0;
- for(Node x : ar)
- {
- length = length + x.l;
- sum = sum + x.w * ( length);
- }
- System.out.println(sum);
- }
- }
- class Node{
- int w,l;
- float dif;
- Node(int w,int l)
- {
- this.w = w;
- this.l = l;
- dif = (float)w / (float)l;
- }
- public String toString()
- {
- return this.w+" "+this.l+" "+this.dif;
- }
- }
- class Sort implements Comparator<Node>
- {
- public int compare(Node a , Node b)
- {
- if(a.dif - b.dif != 0)
- return (int)Math.signum(b.dif - a.dif);
- else return (int)Math.signum(b.w - a.w);
- }
- }
Add Comment
Please, Sign In to add comment