<?php
	// Staring straight up into the sky ... oh my my
	error_reporting(-1);
	mb_internal_encoding('utf-8');

	$amount = 54500;
	$bills = array(
		100 => 23,
		500 => 5,
		1000 => 0,
		5000 => 200
	);
	
	$result = array_fill_keys(array_keys($bills), 0);
	
	krsort($bills);
	foreach($bills as $key => $value){
		$flg = true;
		while($value>0 && $flg){
			if(($amount - $key)<0){
				$flg = false;
			}else{
				$amount -= $key;
				$value--;
				$result[$key]++;
			}
		}
	}

	$resultStr = "";
	foreach ($result as $key => $value) {
		if($value != 0){
			$resultStr = $resultStr."{$value}x{$key} ";
		}
	}
	echo $resultStr."\n";
	
?>