24 lines
471 B
C++
24 lines
471 B
C++
// Minimizing Coins
|
|
|
|
#include<bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
int main() {
|
|
int n, x;
|
|
cin >> n >> x;
|
|
vector<int> dp(x + 1, INT_MAX - 5);
|
|
dp[0] = 0;
|
|
for (int i{}; i < n; i++) {
|
|
int c; cin >> c;
|
|
for (int j = c; j <= x; j++) {
|
|
if (j >= c) {
|
|
dp[j] = min(dp[j - c] + 1, dp[j]);
|
|
}
|
|
}
|
|
}
|
|
if (dp[x] != INT_MAX - 5) cout << dp[x] << endl;
|
|
else cout << -1 << endl;
|
|
return 0;
|
|
}
|