#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18 + 7;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int MOD2 = 1e9 + 9;
const int MAXXX = 1e3 + 5;
const int MAXXXx = 1e3 + 5;
const int OFFSET = 200;
void Make_set(vector<int>& v)
{
set<int> s(v.begin(), v.end());
v.assign(s.begin(), s.end());
}
int Pow(int n, int k, int mod)
{
int res = 1;
while (k > 0)
{
if (k % 2 == 1)
{
res = (res * n) % mod;
}
n = (n * n) % mod;
k /= 2;
}
return res;
}
vector<pair<int, vector<int>>> dp(MAXXX);
int x[MAXXX];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T ;
// cin >> T;
T = 1;
for (int K = 0; K < T; K++)
{
map<int, int> mp;
int n, m;
cin >> n >> m;
int a[n], b[m];
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
for(int i = 0; i < m; i++)
{
cin >> b[i];
mp[b[i]]++;
}
dp[0].first = 1;
for(int i = 0; i < m; i++)
{
for(int j = MAXXX; j >= b[i]; j--)
{
if(dp[j - b[i]].first > 0)
{
dp[j].first++;
dp[j].second.push_back(b[i]);
x[j] = j - b[i];
if(mp[j - b[i]])
{
dp[j].second.push_back(x[j]);
}
}
}
}
// for(int i = 0; i < MAXXX; i++)
// {
// if(dp[i].first)
// {
// cout << i << endl;
// for(int j = 0; j < dp[i].second.size(); j++)
// {
// cout << dp[i].second[j] << ' ';
// }
// cout << endl << "_______________" << endl;
// }
// }
if(n == 1)
{
if(dp[a[0]].first > 0)
{
cout <<"YES";
}
else cout << "NO";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |