Welcome to Fluther.
You’ve left out far too much information. The mass of the apple is critical.
You should also state that the forward throw is at 0° relative to the motion of the train (if that is your intent), or any allowed offset.
The direction of the throw’s vertical angle is also critical. An apple thrown at 45° relative to the ground (and I suppose we should also assume a flat plain / plane surface for the train tracks, too?) will likely go farthest.
As @elbanditoroso notes, ambient wind is also a factor.
Finally, it is also critical to know the strength of the thrower, or at least the force imparted by the thrower. “A toss forward” by a child is not the same “throw” as a Major League baseball pitcher’s best effort.
It’s also necessary to know the height of the thrower relative to the ground.
Really, you need to sort of sketch this out on paper first to see what a solution requires.