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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#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;
void rec(int sum = 0, int i = 1){
if(sum == x)f=1;
if(i > m)return;
rec(sum, i+1), rec(sum+b[i], i+1);
}
void solve() {
nikita
cin >> n >> m;
FOR(1, n)cin >> x;
FOR(1, m)cin >> b[i];
rec();
if(!f)cout << "NO\n";
else 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... |