Tap here to switch tabs
Problem
Submissions

Problem: Eliminate Maximum Number of Monsters

med
30 min
Try to solve the Eliminate Maximum Number of Monsters problem.

Statement

You are playing a video game where you must defend a city against a horde of nn monsters. You are given two 00 indexed integer arrays dist and speed, both of length nn. Here, dist[i] represents the initial distance of the iextthi^{ ext{th}} monster from the city, and speed[i] represents the speed of the iextthi^{ ext{th}} monster.

You possess a weapon that can eliminate one monster at a time. The weapon is fully charged at minute 00 and takes exactly 11 minute to recharge after each use. Consequently, you can eliminate a monster at minute 00, another at minute 11, and so on.

The monsters move continuously toward the city at their respective speeds. You lose the game if any monster reaches the city (meaning its distance becomes less than or equal to 00) before you can eliminate it. If a monster reaches the city at the exact same minute you fire at it, you still lose.

Return the maximum number of monsters you can eliminate before losing, or nn if you can eliminate all of them.

Constraints:

  • n ==== dist.length ==== speed.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq dist[i], speed[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Eliminate Maximum Number of Monsters

med
30 min
Try to solve the Eliminate Maximum Number of Monsters problem.

Statement

You are playing a video game where you must defend a city against a horde of nn monsters. You are given two 00 indexed integer arrays dist and speed, both of length nn. Here, dist[i] represents the initial distance of the iextthi^{ ext{th}} monster from the city, and speed[i] represents the speed of the iextthi^{ ext{th}} monster.

You possess a weapon that can eliminate one monster at a time. The weapon is fully charged at minute 00 and takes exactly 11 minute to recharge after each use. Consequently, you can eliminate a monster at minute 00, another at minute 11, and so on.

The monsters move continuously toward the city at their respective speeds. You lose the game if any monster reaches the city (meaning its distance becomes less than or equal to 00) before you can eliminate it. If a monster reaches the city at the exact same minute you fire at it, you still lose.

Return the maximum number of monsters you can eliminate before losing, or nn if you can eliminate all of them.

Constraints:

  • n ==== dist.length ==== speed.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq dist[i], speed[i] ≤105\leq 10^5