Such problems can also be formulated in a concise way with Clingo ASP (answer set programming):
We define feasible combinations of depart and return trips with the resulting costs
We minimize the costs
% ---------- INPUT ----------
d(1,10). d(2,7). d(3,13). d(4,12). d(5,4).
r(1,5). r(2,12). r(3,7). r(4,10). r(5,12).
% ---------- CHOICE RULE ----------
1 { trip(I,J,D+R) : d(I,D), r(J,R), J>=I } 1.
% ---------- OPTIMIZATION ----------
#minimize { C : trip(I,J,C) }.
% ---------- OUTPUT ----------
#show trip/3.
Output: (run the code online)
clingo version 5.7.2 (6bd7584d)
Reading from stdin
Solving...
Answer: 1
trip(1,1,15)
Optimization: 15
Answer: 2
trip(2,3,14)
Optimization: 14
OPTIMUM FOUND
Models : 2
Optimum : yes
Optimization : 14
Calls : 1
Time : 0.037s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.000s