// #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;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
71 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
67 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
472 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
71 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
67 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |