This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool can(vector<int> &a, vector<int> &b)
{
unordered_map<int, int> cnt;
for(int i : b)
{
cnt[i]++;
}
for (int j : a) {
vector<int> dp(j + 1, 0);
dp[0] = 1;
for(auto [i, r] : cnt)
{
for(int i = j; i >= 0; i--)
{
if(dp[i])
{
for(int j = 1; j <= r && i + j * i <= j; j++)
{
dp[i + j * i] = 1;
}
}
}
}
if(dp[j] == 0)
{
return false;
}
}
return true;
}
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(auto &i : a)
{
cin >> i;
}
for(auto &i : b)
{
cin >> i;
}
cout << (can(a, b) ? "YES" : "NO");
}
# | 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... |