Three points:
Optimization problems often involve maximizing or minimizing a formula. Write the formula first, then think about how to evaluate it efficiently.
Two pointers work when moving one pointer in a certain direction guarantees you don't miss the answer. This requires reasoning about what happens to your objective function.
Sometimes algebraic reasoning (which variable limits the result) guides your algorithm choice.