[BOJ] 7579 앱

Time Lapse :15min 11sec

7579.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <vector>
using namespace std;
int dp[10000001];
int n, m, ans = 987654321, sum;
int mem[100];
int c;
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i < 10000001; i++)
dp[i] = 987654321;
for(int i = 0; i < n; i++)
scanf("%d",&mem[i]);
for(int i = 0; i < n; i++) {
scanf("%d",&c);
for(int j = sum += mem[i]; j >= mem[i]; j--)
dp[j] = min(dp[j], dp[j - mem[i]] + c);
}
for(int i = m; i < 10000001; i++)
ans = min(ans,dp[i]);
printf("%d",ans);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/09/02/PS/BOJ/7579/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.