Just curious about different perspectives to approach this problem

Revision en1, by Ranchoddas_Chanchad, 2025-01-30 07:15:54

Problem Statement

You are given two lists of integers, T and A, where:

  1. t[i] represents the launch time of the i-th missile.
  2. a[i] represents the position where you need to be to watch the i-th missile launch.

Starting at position 0, you can move up to X units per second. Your objective is to maximize the number of launches you can watch. You can watch a launch if you are at the required position a[i] exactly at the time t[i].


Input Format

The first line contains two integers N and X—the number of missile launches and your maximum speed.

The second line contains N integers t1, t2, ..., tn — the times of the launches in the mission in increasing order.

The third line contains N integers a1, a2, ..., an — the positions along the boundary where you need to be to watch each launch closely.


Output Format

Print the maximum number of launches that you can watch closely.


Constraints

  • ( 1 \leq N \leq 2 \times 10^5 )
  • ( 1 \leq X \leq 10^6 )
  • ( 1 \leq t \leq 10^9 )
  • ( -10^9 \leq a \leq 10^9 )

Sample Testcase 1

Input

1 2  
3  
7  

Output

0  

Explanation

He cannot reach any missile launch positions on time, so he can't watch any missile attacks.


Sample Testcase 2

Input

3 2  
5 10 15  
7 17 29  

Output

2  

Explanation

  • Initial Position: Start at position 0.
  • At time 5: Go to 7 with speed 2 for 3.5 seconds to reach there just in time to watch the missile launch.
  • At time 10: Immediately move to 17 from 7, traveling at your maximum speed of 2 units per second, arriving precisely as the second launch occurs.
  • Therefore, the maximum number of launches you can monitor closely is 2.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Ranchoddas_Chanchad 2025-01-30 07:20:06 12
en2 English Ranchoddas_Chanchad 2025-01-30 07:19:07 129
en1 English Ranchoddas_Chanchad 2025-01-30 07:15:54 1935 Initial revision (published)