Let d is the distance that I want to swim. Diestance by Pythagorean Theorem is . Since I swim 3km per hour than time for swimming d is

I walk with speed 9 km per hour therefore time for walking is

Total time is (this is your time function).

f'(x)=0 when or . This gives

Therefore, distance to swim is

Distance to walk is

Time needed is

Free Math Site