Hemant Bhaiya and The Jumping Frog

0

0 votes
Problem

Hemant bhaiya recently started learning unity and made a cool 3-D game. The game is called The Jumping Fog. Here is how the game works.

There are N lilypads in a lake and each lilypad has 3 properties H[i], X[i]  and Y[i].

  • H[i] - The height of the lilypad.
  • Y[i] - When a frog jumps from this lilypad, it cannot jump higher than Y[i] i.e. if a frog is at lilypad i then it can only jump to a lilypad j if H[j] <= H[i] + Y[i], where 1 <= i < j <= n.
  • X[i] - This is the minimum throwing distance of the lilypad. When a frog jumps from this lilypad it can only jump to a lilypad at a distance greater than X[i] i.e. if a frog is at lilypad i then it can only jump to a lilypad j if j >= i + X[i], where 1 <= i < j <= n.

Rules of the game -

  • The frog can start from any arbitrary position.
  • The frog can only move forward i.e. if a frog is at position i it can only jump to a lilypad at position j > i.
  • The frog doesn't like going down so it can only go to a lilypad if it's height is greater than or equal to the height current lilypad.
  • Every lilypad has C[i] coins on it and the goal of the game is to collect as many coins as you can.

After making the game Hemant bhaiya wanted to know that what is the maximum points that a person can score in a particular game and the first person to solve this problem will get a treat by him.

Input Format -

  • The first line contains N, the number of lilypads.
  • The next line contains N space-separated integers describing the array H.
  • The next line contains N space-separated integers describing the array X.
  • The next line contains N space-separated integers describing the array Y.
  • The next line contains N space-separated integers describing the array C.

Output Format -

For each test case print the maximum score possible.

Constrains -

  • 1N105
  • 1Hi,Ci109
  • 0Yi109
  • 1XiN

Problem Setter - Puneet Rai

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?