Background
Captain Hansen wants to navigate with his little barge from Hamburg downstream to Cuxhaven on the river Elbe. During this journey he must take the tide into account. When the tide is falling the water flows to the North Sea and speeds up the ship. When the tide is rising the drift of the tide reduces the real speed. The drift is not constant, but varies over the time. Captain Hansen now wants to know, when to start in order to minimize the time for the journey.
Of course, there are deadlines to meet and Hansen runs a "just in time" service, so the arrival should be as late as possible, but not after a given deadline.
The Problem
Create a program which calculates the optimal time t of departure. The optimal time depends on two criteria:
1. Departing at t guarantees that Hansen will reach Cuxhaven before a given deadline (i.e., arrival time < deadline).
2. For departure time t, the time for the journey is minimal.
3. If multiple such departure times exist, Hansen picks the latest one that will bring him to Cuxhaven The distance between Hamburg and Cuxhaven is 100 km. The ship moves with a constant speed of 10 km/h through water (without drift!). The real speed (speed over ground) is calculated by adding or subtracting the drift speed. The drift has the same speed and direction on the whole river at any time. Speed and direction change not more than once per minute and remain constant until the next change.