This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define nots0fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vl vector<ll>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(v) v.begin(), v.end()
#define mid(a, b) ((a) + (b)) / 2
using namespace std;
mt19937 rng(time(NULL)); // rng()%(r - l + 1) + l
const int MX = 1e5 + 5 , inf = 1e9 + 99, sz = 5005, mod = 1000000007, N = 1e6 + 31, MOD = 998244353;
const ll INF = 100000000000000007;
ll v[MX], sg[MX << 2];
// struct DSU
// {
// vl e;
// void init(ll node){
// e.assign(node + 1, -1);
// }
// ll get(ll node){
// if(e[node] < 0) return node;
// return e[node] = get(e[node]);
// }
// bool unite(ll x, ll y){
// x = get(x);
// y = get(y);
// if(x == y) return false;
// if(e[x] > e[y]){
// swap(e[x], e[y]);
// }
// e[x] += e[y];
// e[y] = x;
// return true;
// }
// };
struct DSU{
vl e;
void init(ll node){
e.assign(node + 1, -1);
}
ll get(ll x){
if(e[x] < 0) return x;
return e[x] = get(e[x]);
}
bool unite(ll x, ll y){
x = get(x);
y = get(y);
if( x == y ) return false;
if(e[x] > e[y]){
swap(e[x], e[y]);
}
e[x] += e[y];
e[y] = x;
return true;
}
};
void solve () {
ll n, m;
cin >> n >> m;
vl a(n), b(m);
for(int i = 0; i < n; i ++){
cin >> a[i];
}
for(int i = 0; i < m; i ++){
cin >> b[i];
}
for(int bit = 1; bit < (1 << m); bit ++){
ll sum = 0;
for(int i = 0; i < m; i ++){
if(bit & (1 << i)){
sum += b[i];
}
}
if(sum == a[0]){
cout << "YES";
return ;
}
}
cout << "NO";
}
signed main(){
//auto begin = std::chrono::high_resolution_clock::now();
nots0fast
int test = 1;
//cin >> test;
for(int tst = 1; tst <= test; tst++) {
//cerr << "Case : \n";
solve();
cout << endl;
}
// auto end = std::chrono::high_resolution_clock::now();
// auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
// cerr << elapsed.count() * 1e-9 << endl;
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... |