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;
#define all(a) a.begin(),a.end()
#define ll long long
#define pb push_back
#define nl '\n'
#define popb pop_back()
#define sz size()
#define ld long double
#define ull unsigned long long
#define F first
#define S second
#define fix fixed<<setprecision
#define pii pair<int,int>
#define E exit (0)
#define int1 long long
const int inf=1e9;
int main() {
//freopen("planting.in","r",stdin);
//freopen("planting.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
int a[n+1],b[m+1];
for (int i=1;i<=n;i++) {
cin>>a[i];
}
for (int i=1;i<=m;i++) {
cin>>b[i];
}
vector<bool>dp(1001);
dp[0]=true;
for (int i=1;i<=m;i++) {
for (int j=1000;j>=0;j--) {
if (j+b[i]>1000||!dp[j]) {
continue;
}
dp[j+b[i]]=true;
}
}
for (int i=1;i<=n;i++) {
if (!dp[a[i]]) {
cout<<"NO";
return 0;
}
}
cout<<"YES";
}
# | 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... |