#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, M;
vector<ll> a, b;
//vector<ll> DP;
bool calc(ll x, ll w){
if(w==0){return true;}
if(w<0){return false;}
if(x==0){return false;}
return (calc(x-1, w-b[x-1]) or calc(x-1, w));
}
int main() {
cin>>N>>M;
a.resize(N);
b.resize(M);
for(ll i=0;i<N;i++){cin>>a[i];}
for(ll i=0;i<M;i++){cin>>b[i];}
//DP.resize(1000, vector<ll>(M));
if(calc(M, a[0])){cout<<"YES";}
else{cout<<"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... |