Solved.ac Class3++
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] split = br.readLine().split(" ");
int n = Integer.parseInt(split[0]);
int target = Integer.parseInt(split[1]);
int[] coins = new int[n];
for (int i = 0; i < n; i++) {
coins[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(coins);
int count = 0;
int selectCoinPosition = n - 1;
while (target != 0) {
int selectCoin = coins[selectCoinPosition];
if (selectCoin <= target) {
while (target >= selectCoin) {
count++;
target -= selectCoin;
}
}
selectCoinPosition--;
}
System.out.println(count);
}
}
성공
fun main() {
val split = readln().split(" ")
val n = split[0].toInt()
var target = split[1].toInt()
val coins = Array(n) { 0}
for (i in 0..<n) {
coins[i] = readln().toInt()
}
coins.sort()
var count: Int = 0
var selectCoinPosition = n - 1
while (target != 0) {
val selectCoin = coins[selectCoinPosition]
if (selectCoin <= target) {
while (target >= selectCoin) {
target -= selectCoin
count++
}
}
selectCoinPosition--
}
print(count)
}