Skip to content

Instantly share code, notes, and snippets.

@ryosism
Created September 27, 2016 15:45
Show Gist options
  • Save ryosism/64825a5b1d47fc8872ef088e8f1eccd6 to your computer and use it in GitHub Desktop.
Save ryosism/64825a5b1d47fc8872ef088e8f1eccd6 to your computer and use it in GitHub Desktop.
【Level.1】CTOからの挑戦状2016 2nd~GistURL回答~
// 手続き
function selectOptimumCombination(amount, myCoupons) {
var selectedCoupons = [0, 0, 0];
if(amount>1000){
while(myCoupons[0]>0){
if(amount<500) break;
amount=amount-500;
myCoupons[0]--;
selectedCoupons[0]++;
}
while(myCoupons[1]>0){
if(amount<200) break;
amount=amount-200;
myCoupons[1]--;
selectedCoupons[1]++;
}
while(myCoupons[2]>0){
if(amount<100) break;
amount=amount-100;
myCoupons[2]--;
selectedCoupons[2]++;
}
}
return selectedCoupons;
}
// ケース3
console.log(selectOptimumCombination(1210, [2, 1, 3]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment