Блог пользователя Ranchoddas_Chanchad

Автор Ranchoddas_Chanchad, история, 19 часов назад, По-английски

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<=N<=2*1e5

1<=X<=1e6

1<=t[i]<=1e9

-1e9<=a[i]<=1e9

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.
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
19 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Ranchoddas_Chanchad (previous revision, new revision, compare).

»
15 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Disclaimer: not tested

  1. Since we start at position 0 we can immediately remove any launches that are not reachable at all, then we can pretend we can start anywhere

  2. Being able to move X distance per second is equivalent to being able to move 1 per second and all time values are multiplied by X, I'll describe how to solve the problem if X=1

  3. Plot the points on a graph where x-axis is time and y-axis is position. Imagine for point (t1, a1) the region of all possible launches you could visit after this one. Its boundaries should form a "<" shape going out of its right. Then, the problem is to find the maximum length subsequence such that the "<"-shaped region for each point contains the one after it

  4. After rotating the graph 45 degrees so the boundaries are horizontal/vertical instead of diagonal, this problem can easily be solved with a sweepline approach

  • »
    »
    12 часов назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Yupp! It's cool I think it will work as evry case is being covered. And yeah that's a nice way to approach this problem geometrically.... actually what I was thinking was too complicated as I never thought like we can rotate the axes so some sort of fenwick tree or treaps were must to solve it but now...thanks a lot man!