A Simple Algorithm
At most N stamps needed, etc.
for a = 0, …, N { for b = 0, …, N { for c = 0, …, N { if (5a+4b+c == N && a+b+c is new min) {retain (a,b,c);}}}output retained triple;
Time: O(N3)(Not too hard to see some optimizations, but we’re after bigger fish…)