Say Alice and Bob both like, and can make, both gizmos and widgets. Alice takes 5 hours to make a gizmo and 6 hours to make a widget. Bob takes 8 hours to make a gizmo and 7 hours to make a widget.
Consider a 100-hour period of their work. If each person likes gizmos and widgets equally, so that they want a balance:
Alice is more efficient at both tasks. Alice is better at making gizmos than widgets. Bob is better at making widgets than gizmos.
If Alice and Bob trade:
Then both of them are better off. This situation arose sith Bob has a "comparative advantage" in making widgets.
None of the maths here exploited the assumption that Alice and Bob are different people. You get the same situation with a comparative advantage of one person's changing abilities over time. In that case, there is no actual trade, just an accumulation of value within your own life.
Say you consistently value both exercise and study. Studying gives 1 unit of knowledge per 10 minutes. Exercising gives 1 unit of fitness per 5 minutes, when the gym is open, or per 15 minutes, when the gym is closed.
Consider 1 hour of open gym, and 1 hour of closed gym. If you don't "trade with yourself" (i.e. apply the allocation principle I'm justifying here):
If you do trade with yourself:
This is the fancy mathematical justification behind the rule that if a task (done efficiently) depends on a resource, when the resource is available, you should prefer that task over others disproportionately to its value.