Sinbad is traveling along a path of N points, numbered 0 to N-1. He starts at point 0 with an initial energy E and aims to reach the final point N-1.
Along the path, there are two factors that affect his journey:
1) Energy Stations: An array energy where energy[i] is the amount of energy Sinbad gains upon arriving at point i. He can only gain energy from a station once.
2) Wind: An array wind where wind[i] is the wind speed at point i. The wind affects the cost to travel from point i to i+1.
If wind[i] is positive (helpful wind), the cost to move is 0.
If wind[i] is negative (hindering wind), the cost to move is 1 + abs(wind[i]).
If wind[i] is zero, the base cost to move is 1.
On each day, Sinbad is at a point i and attempts to move to i+1.
1) If his current energy is greater than or equal to the travel cost, he pays the cost, moves to point i+1, and then immediately gains the energy energy[i+1] from the new point.
2) If his current energy is less than the travel cost, he is stuck and cannot move. The journey fails.
Your task is to find the maximum energy Sinbad can have upon arriving at point N-1. If he can never reach the final point, return -1.
Input Format:
The first line contains two space-separated integers: N and E (initial energy).
The second line contains N space-separated integers for the energy array.
The third line contains N space-separated integers for the wind array.
Output Format:
Print a single integer representing the maximum energy at the destination.
If the destination is unreachable, print -1.
Note:
The journey is a linear simulation from left to right.