<?php
check(120, [10, 60, 100]);
check(740, [10, 50, 100, 500, 1000]);

function check($target, $notes) {

	$inf = 999999;
	$counts = [0 => 0];

	foreach (range(1, $target) as $n) {
		$counts[$n] = $inf;
		foreach ($notes as $note) {
			if ($n >= $note) {
				$cur_count = $counts[$n-$note] + 1;
				if ($cur_count < $counts[$n]) {
					$counts[$n] = $cur_count;
				}
			}
		}
	}

	if ($counts[$target] == $inf) {
		echo "impossible\r\n";
		return;
	}

	$result = [];
	while ($target > 0) {
		foreach ($notes as $note) {
			if ($counts[$target-$note] == $counts[$target]-1) {
				$result[] = $note;
				$target -= $note;
				break;
			}
		}
	}
	echo implode(', ', $result), "\r\n";
}