Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n, m;
- cin >> n >> m;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- vector<vector<bool>> dp(n + 1, vector<bool>(m + 1));
- dp[0][0] = true;
- for (int i = 1; i <= n; ++i) {
- for (int j = 0; j <= m; ++j) {
- dp[i][j] = dp[i - 1][j];
- if (a[i - 1] <= j && dp[i - 1][j - a[i - 1]]) dp[i][j] = true;
- }
- }
- cout << (dp[n][m] ? "YES\n" : "NO\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement