20250712 baekjoon

This commit is contained in:
songyc macbook 2025-07-12 17:39:54 +09:00
parent 7f66808147
commit fe95a079e4
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, K;
scanf("%d %d",&N, &K);
int* coin = (int*)malloc(sizeof(int)*N);
for(int i=0; i<N; i++){
scanf("%d",&coin[i]);
}
int k_diff = K, count = 0;
for(int i=N-1; i>=0; i--){
if(coin[i]<=k_diff){
count += k_diff/coin[i];
k_diff = k_diff%coin[i];
}
}
printf("%d\n",count);
free(coin);
return 0;
}

View File

@ -0,0 +1,9 @@
export {}
const input: string[] = require("fs").readFileSync(0, "utf8").toString().trim().split('\n');
const arr: number[] = input[1].split(" ").map(Number).sort((a,b) => a-b);
let [sum, acc] = [0,0];
for(let v of arr){
acc += v;
sum += acc;
}
console.log(sum);