Your algorithm does not show how to select di. If you pick the smallest possible denomination first, then consider S=6 with a cash box of 2 x 1 1 x 5 The algorithm will pick both 1's and then fail because all that's left is the 5.
If you pick the largest possble di then try S=60 with a cash box of 1 x 50 3 x 20 This will take the 50 and then fail because there are no 10s.