Problem 978
Eliminate Maximum Number of Monsters
Medium · 20 pts · Array, Greedy, Sorting
Problem
Monster i starts at distance DIST[i] from your city and walks toward it at SPEED[i] per minute. Your weapon kills one monster per shot and needs one minute to recharge, and it is fully charged at minute 0. You lose as soon as a monster reaches the city; a monster arriving at the same moment the weapon becomes ready still wins. Count how many monsters you can eliminate before losing. Sort the arrival times ceil(DIST / SPEED) and shoot in that order: shot k happens at minute k.
Input
The first line contains N. The second line contains the distances. The third line contains the speeds.
Output
Print the maximum number of monsters eliminated.
Constraints
1 <= N <= 100000; 1 <= DIST[i], SPEED[i] <= 10^5
Example input
3 1 3 4 1 1 1
Example output
3
Explanation
With distances 1 3 4 and speeds 1 1 1, the monsters arrive at minutes 1, 3 and 4. Shooting at minutes 0, 1 and 2 kills them all, so the answer is 3.