# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1205510 | tamzid | 은행 (IZhO14_bank) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
#define pb push_back
#define F first
#define S second
#define vii vector<int>
#define vl vector<long long>
#define cinv(v) for (auto &it : v) cin >> it;
#define coutv(v) for (auto &it : v) cout << it << " "; cout << '\n';
#define dbg_var(x,y) cout<<y<<"# Debugging: "<<x<<'\n';
using namespace std;
//using namespace __gnu_pbds;
//template<class T> using ordset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int maxn = 1020;
void solve()
{
int n,m;
cin>>n>>m;
vii a(n),b(m);
for(int i=0;i<n;++i)
cin>>a[i];
for(int i=0;i<m;++i)
cin>>b[i];
vector<int> dp(maxn,1e9);
dp[0] = 0;
for(int i=1;i<=maxn;++i)
{
for(int j=0;j<m;++j)
{
if(b[j] <= i)
{
dp[i] = min(dp[i],dp[i - b[j]]+1);
}
}
}
for(int i=0;i<n;++i)
{
int aa = a[i];
if(dp[aa] != 1e9)
{
continue;
}
else
{
cout<<"NO\n";
return;
}
}
cout<<"YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
//int t;cin>>t;while(t--)
solve();
return 0;
}