27 lines
486 B
C++
27 lines
486 B
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
|
|
int main() {
|
|
int n, w;
|
|
cin >> n >> w;
|
|
vector<int> a(n);
|
|
for (int i = 0; i < n; i++) cin >> a[i];
|
|
|
|
vector<int> dp(w + 1, 1e9);
|
|
dp[0] = 0;
|
|
|
|
for (int j = 0; j < n; j++) {
|
|
for (int i = a[j]; i <= w; i++) {
|
|
dp[i] = min(dp[i], dp[i - a[j]] + 1);
|
|
}
|
|
}
|
|
|
|
if (dp[w] == 1e9) cout << -1 << endl; // ÎÞ½â
|
|
else cout << dp[w] << endl;
|
|
|
|
return 0;
|
|
}
|
|
|