You have learned the foundations of greedy algorithms:
Greedy makes locally optimal choices without reconsidering.
It requires greedy choice property (safe to be greedy) and optimal substructure (subproblems combine correctly).
Sorting is often the key step. The right sort order makes greedy work.
When greedy fails, you will find counterexamples on small inputs. Switch to DP. Good job on finishing this section. In the next section, I will show you how to prove greedy correctness using exchange arguments.