baekjoon 20260103

This commit is contained in:
songyc macbook 2026-01-03 22:28:18 +09:00
parent 686fb84ef8
commit b6564903d1
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#include <stdio.h>
#define MAX_COST 100000
int min(int a, int b) {
return a > b ? b : a;
}
int dp[1101];
int main() {
int C, N;
scanf("%d %d",&C, &N);
dp[0] = 0;
for(int i=1; i<=C+100; i++) dp[i] = MAX_COST;
while(N--) {
int cost, man;
scanf("%d %d",&cost, &man);
for(int c=man; c<C+101; c++) dp[c] = min(dp[c], dp[c-man] + cost);
}
int ans = MAX_COST;
for(int i=C; i<C+101; i++) ans = min(ans, dp[i]);
printf("%d\n",ans);
return 0;
}

View File

@ -0,0 +1,8 @@
func solve() {
guard let input = readLine() else { return }
var nums = input.split(separator: " ").compactMap{Int($0)}
nums.sort()
print(nums[1])
}
solve()