You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster from the city.

The monsters walk toward the city at a constant speed. The speed of each monster is given to you in an integer array speed of size n, where speed[i] is the speed of the ith monster in kilometers per minute.

You have a weapon that, once fully charged, can eliminate a single monster. However, the weapon takes one minute to charge.The weapon is fully charged at the very start.

You lose when any monster reaches your city. If a monster reaches the city at the exact moment the weapon is fully charged, it counts as a loss, and the game ends before you can use your weapon.

Return the maximum number of monsters that you can eliminate before you lose, or n if you can eliminate all the monsters before they reach the city.

&nbsp;
Example 1:

Input: dist = [1,3,4], speed = [1,1,1]
Output: 3
Explanation:
In the beginning, the distances of the monsters are [1,3,4]. You eliminate the first monster.
After a minute, the distances of the monsters are [X,2,3]. You eliminate the second monster.
After a minute, the distances of the monsters are [X,X,2]. You eliminate the thrid monster.
All 3 monsters can be eliminated.

Example 2:

Input: dist = [1,1,2,3], speed = [1,1,1,1]
Output: 1
Explanation:
In the beginning, the distances of the monsters are [1,1,2,3]. You eliminate the first monster.
After a minute, the distances of the monsters are [X,0,1,2], so you lose.
You can only eliminate 1 monster.


Example 3:

Input: dist = [3,2,4], speed = [5,3,2]
Output: 1
Explanation:
In the beginning, the distances of the monsters are [3,2,4]. You eliminate the first monster.
After a minute, the distances of the monsters are [X,0,2], so you lose.
You can only eliminate 1 monster.


&nbsp;
Constraints:


	n == dist.length == speed.length
	1 &lt;= n &lt;= 105
	1 &lt;= dist[i], speed[i] &lt;= 105


class Solution:
    def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int:
        for i, t in enumerate(sorted([(d - 1) // s for d, s in zip(dist, speed)])):
            if i > t:
                return i
        return len(dist)  
class Solution {
    public int eliminateMaximum(int[] dist, int[] speed) {
        
        int n = dist.length;
        
        int[] time = new int[n];
        
        for(int i = 0; i < n; i++){
            time[i] = (int)Math.ceil(dist[i] * 1.0 / speed[i]);
        }
        
        Arrays.sort(time);
        
        int eliminated = 0;
		
		// At i = 0, minute = 0 ( therefore, we can use i in place of minute )
        
        for(int i = 0; i < n; i++){
			 
            if(time[i] > i){  // At ith minute, eliminate the first monster arriving after ith minute
                eliminated++;
            }else{
                break; // Monster reached the city
            }
        }
        
        return eliminated;
    }
}
class Solution {
public:
    int eliminateMaximum(vector<int>& dist, vector<int>& speed) {
        priority_queue<double, vector<double>, greater<double>> pq;
        
        for(int i = 0; i < dist.size(); ++i)
            pq.push(ceil((double)dist[i] / speed[i] ));
        
        int t = 0;
        while(pq.size() && pq.top() > t++) pq.pop();
        return dist.size() - pq.size();
    }
};
/**
 * @param {number[]} dist
 * @param {number[]} speed
 * @return {number}
 */
var eliminateMaximum = function(dist, speed) {
    let res = 0;
    let len = dist.length;
    let map = new Map();
    for(let i=0; i<len; i++){
        // the last time to eliminate
        let a = Math.ceil(dist[i] / speed[i]);
        if(map.has(a)){
            let c = map.get(a);
            c ++;
            map.set(a, c);
        }else{
            map.set(a, 1);
        }
    }

    let keys = Array.from(map.keys());
    keys.sort((a, b) => a-b);
    // time to eliminate
    let t = 0;
    for(let i=0; i<keys.length; i++){
        let c = map.get(keys[i]);
        if(c > keys[i]-t){
            res += keys[i]-t;
            break;
        }else{
            res += c;
            t += c;
        }
    }

    return res;
};
Eliminate Maximum Number of Monsters