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;
int n, m;
vector<int> a, b;
const int N = 1e3 + 4;
const int M = 20 + 5;
// int dp[N][M];
bool f(int pos, int sum){
if(pos == m){
if(sum == a.front())
return 1;
return 0;
}
if(f(pos + 1, sum + b[pos]))
return 1;
if(f(pos + 1, sum))
return 1;
return 0;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
// memset(dp, -1, sizeof dp);
cin >> n >> m;
a.resize(n);
b.resize(m);
for(int &i : a)
cin >> i;
for(int &i : b)
cin >> i;
cout << (f(0, 0) ? "YES" : "NO") << "\n";
return 0;
}
# | 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... |