package leetcode;

/**
 * https://leetcode.com/problems/car-fleet/
 */
public class Problem853 {
    public int carFleet(int target, int[] position, int[] speed) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem853 prob = new Problem853();
//        System.out.println(prob.carFleet(12, new int[]{10, 8, 0, 5, 3}, new int[]{2, 4, 1, 1, 3})); // 3
//        System.out.println(prob.carFleet(12, new int[]{10, 7, 0, 5, 3}, new int[]{2, 4, 1, 1, 3})); // 4
//        System.out.println(prob.carFleet(12, new int[]{1, 2, 3, 4, 5}, new int[]{5, 4, 3, 2, 1})); // 1
//        System.out.println(prob.carFleet(15, new int[]{4, 5}, new int[]{2, 1})); // 1
//        System.out.println(prob.carFleet(10, new int[]{2, 4}, new int[]{3, 2})); // 1
        System.out.println(prob.carFleet(31, new int[]{5, 26, 18, 25, 29, 21, 22, 12, 19, 6}, new int[]{7, 6, 6, 4, 3, 4, 9, 7, 6, 4})); // 6
    }
}

@@ -12,16 +12,94 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -247,140 +247,64 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem853 prob = new Problem853
+TreeMap%3CInteger, Double%3E map = new TreeMap%3C%3E
 ();%0A
-//
         
 Syst
@@ -303,635 +303,481 @@
     
-System.out.println(prob.carFleet(12, new int%5B%5D%7B10, 8, 0, 5, 3%7D, new int%5B%5D%7B2, 4, 1, 1, 3%7D)); // 3%0A//        System.out.println(prob.carFleet(12, new int%5B%5D%7B10, 7, 0, 5, 3%7D, new int%5B%5D%7B2, 4, 1, 1, 3%7D)); // 4%0A//        System.out.println(prob.carFleet(12, new int%5B%5D%7B1, 2, 3, 4, 5%7D, new int%5B%5D%7B5, 4, 3, 2, 1%7D)); // 1%0A//        System.out.println(prob.carFleet(15, new int%5B%5D%7B4, 5%7D, new int%5B%5D%7B2, 1%7D)); // 1%0A//        System.out.println(prob.carFleet(10, new int%5B%5D%7B2, 4%7D, new int%5B%5D%7B3, 2%7D)); // 1%0A        System.out.println(prob.carFleet(31, new int%5B%5D%7B5, 26, 18, 25, 29, 21, 22, 12, 19, 6%7D, new int%5B%5D%7B7, 6, 6, 4, 3, 4, 9, 7, 6, 4%7D)); // 6
+for (int i = 0; i %3C position.length; ++i) %7B%0A            map.put(position%5Bi%5D, (double) (target - position%5Bi%5D) / speed%5Bi%5D);%0A        %7D%0A        double maxSoFar = 0;%0A        int answer = 0;%0A        List%3CDouble%3E timeNeeded = new ArrayList%3C%3E(map.values());%0A        for (int i = position.length - 1; i %3E= 0; i--) %7B%0A            if (timeNeeded.get(i) %3E maxSoFar) %7B%0A                maxSoFar = timeNeeded.get(i);%0A                answer++;%0A            %7D%0A        %7D%0A        return answer;
 %0A   

Solve problem 853