Guest User

LAZYPROG

a guest
May 12th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5.  
  6. import static java.lang.Integer.parseInt;
  7.  
  8. class LAZYPROG {
  9.  
  10.     private static Project projects[] = new Project[100000];
  11.  
  12.     public static void main(String[] args) throws IOException {
  13.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  14.         int t, n, a, b, d;
  15.         String s[];
  16.         t = parseInt(br.readLine());
  17.         initProjects();
  18.         while (t-- > 0) {
  19.             n = parseInt(br.readLine());
  20.             for (int i = 0; i < n; i++) {
  21.                 s = br.readLine().split("\\s");
  22.                 a = parseInt(s[0]);
  23.                 b = parseInt(s[1]);
  24.                 d = parseInt(s[2]);
  25.                 projects[i].init(a, b, d);
  26.             }
  27.             Arrays.sort(projects, 0, n, (p1, p2) -> {
  28.                 if (p1.d == p2.d) {
  29.                     return Integer.compare(p1.a, p2.a);
  30.                 }
  31.                 return Integer.compare(p1.d, p2.d);
  32.             });
  33.             System.out.printf("%.2f", solve(n));
  34.         }
  35.     }
  36.  
  37.     private static double solve(int n) {
  38.  
  39.         return totalProgrammerAmount(n);
  40.     }
  41.  
  42.     private static double totalProgrammerAmount(int n) {
  43.         int timeToComplete, totalRunTime = 0;
  44.         double cost = 0;
  45.         for (int i = 0; i < n; i++) {
  46.             timeToComplete = projects[i].d - totalRunTime;
  47.             if (projects[i].b > timeToComplete) {
  48.                 cost += ((double) (projects[i].b - timeToComplete) / (double) projects[i].a);
  49.                 totalRunTime = projects[i].d;
  50.             } else {
  51.                 totalRunTime += projects[i].b;
  52.             }
  53.         }
  54.         return cost;
  55.     }
  56.  
  57.     private static void initProjects() {
  58.         for (int i = 0; i < 100000; i++) {
  59.             projects[i] = new Project();
  60.         }
  61.     }
  62.  
  63.  
  64.     static class Project{
  65.         int a,b, d;
  66.         public void init(int a, int b, int d) {
  67.             this.a = a;
  68.             this.b = b;
  69.             this.d = d;
  70.         }
  71.     }
  72. }
Add Comment
Please, Sign In to add comment