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 pb push_back
#define sz size()
#define in insert
#define int long long
#define F first
#define up upper_bound
#define S second
#define lb lower_bound
#define pair pair<int, int>
#define all(v) v.begin(),v.end()
#define FOR1(x, n) for(int j = x; j <= n; j ++)
#define FOR(x, n) for(int i = x; i <= n; i ++)
#define FORR(x, n) for(int i = x; i >= n; i --)
#define nikita ios_base::sync_with_stdio(0), cin.tie(0);
int n,m,k,t,ans=0,sum=0,cnt, l, r, x, y, q;
const int N = 1e6+5;
int a[N], b[N], c[N];
vector<int>g[N];
int pref[N];
bool f = 0;
string str;
void rec(int sum = 0, int i = 1, string s = ""){
if(f)return;
if(sum == x){
f=1;
str = s;
return;
}
if(i > m)return;
rec(sum, i+1, s + '0');
if(f)return;
rec(sum+b[i], i + 1, s + '1');
}
void solve() {
nikita
cin >> n >> m;
FOR(1, n)cin >> a[i];
FOR(1, m)cin >> b[i];
FOR(1, n){
x = a[i],f = 0;
k=0, sum = 0;
rec();
if(!f){
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
signed main() {
nikita
int t=1;
FOR(1, t)solve();
}
# | 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... |