I remember as a student being presented with the proof that the shortest distance between two points is a straight line (at least, on a 2 dimensional flat surface). Although it's almost blatantly obvious, it can be formally proved through Calculus of Variations.
However, the quickest route between two points is not necessarily a straight line. Take the example of my walk from my office, on the 3rd floor of EF block at Waikato, to the lecture room G.3.33 on the third floor of G block. Normally it is a short (1 minute) stroll down the third floor corridor in a straight line - the walkway goes from EF building into F building into G building and G.3.33 is straight in front of me. (Those 'in-the-know' will realise I've over-simplified the situation - there are a couple of 22.5 degree bends in the corridor and a few steps to negotiate, but basically it is a straight line between the two.) But not now. There is building work going on in FG link block. This means that the straight-line route is unavailable. Instead, I have to go down three floors, out the door, walk about 100 metres through the rain around the back of F and G buildings to the G front door, then up three flights of stairs, and walk back through the corridor to G.3.33. Total time more like 6 minutes for a distance of about 50 metres.
Here's another example: You are a lifeguard on a beach, say 50 metres from the water, and you see someone in trouble in the sea, say 25 metres off shore and 50 metres along the shore from where you are. Which direction do you run in? You don't run straight towards them, because you know you can run faster than you can swim. Covering the shortest distance in total would mean that you are swimming a longer distance than necessary. It is better to run more along the shore, and enter the water at a point closer to the man in trouble. You cover a longer distance in total, but less of that distance is spent in the water where you are going slowly.
The problem of refraction of light is analogous to the lifesaver description above. The light travels the path that gives the shortest time between two points. Suppose a light ray starts at point A, in air, and ends at point B, in a block of glass. Now, we know that glass has a refractive index. This means that the speed of light in the glass is lower than that in air. The light doesn't travel in a straight line between A and B, but rather in two straight line segments - in a straight line from point A to point C on the surface of the glass, then in a straight line from point C to point B. Where is point C? It turns out that it's such that the total time the ray takes from A to B is minimized. Clever or what? How does it 'know' that this is the shortest path?
Many problems in physics are similar minimization problems.