import java.util.ArrayList;
import java.util.List;
/**
*
* @author Anandh
*
*/
public class MinimumStamp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int stamps[]={90,30,24,15,12,10,5,3,2,1};
int stampAmount = 70;
List<Integer> stampList = minimumStamp(stamps, stampAmount);
System.out.println("Minimum no.of stamps required-->"+stampList.size());
System.out.println("Stamp List-->"+minimumStamp(stamps, stampAmount));
}
public static List<Integer> minimumStamp(int[] stamps, int totalStampAmount){
List<Integer> stampList = new ArrayList<Integer>();
int sumOfStamps = 0;
int remainingStampAmount = 0;
for (int currentStampAmount : stamps) {
remainingStampAmount = totalStampAmount-sumOfStamps;
if(remainingStampAmount%currentStampAmount == 0){
int howMany = remainingStampAmount / currentStampAmount;
while(howMany>0){
stampList.add(currentStampAmount);
howMany--;
}
break;
}else if(totalStampAmount == (sumOfStamps+currentStampAmount)){
stampList.add(currentStampAmount);
break;
}else if(totalStampAmount > (sumOfStamps+currentStampAmount) ){
int howMany = remainingStampAmount / currentStampAmount;
if(howMany>0){
while(howMany>0){
stampList.add(currentStampAmount);
sumOfStamps += currentStampAmount;
howMany--;
}
}else{
stampList.add(currentStampAmount);
sumOfStamps += currentStampAmount;
}
}
}
return stampList;
}
}