This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* -> Written by <-
-----------
|K_A_Z_A_M_A|
|___________|
| ___ |
| (^_^) |
| /( | )\ |
|____|_|____|
H O A N G
*/
#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;
using ll = long long;
using db = long double;
//using int = long long
#define Task ""
#define F first
#define S second
#define eb emplace_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define sall(x, n) x.begin() + 1, x.end() + 1 + n
#define bit(x, i) (((x) >> (i)) & 1)
#define endl '\n'
#define fr(i,a,b) for (int i = (int)(a); i <= (int)(b); ++ i)
#define FR(i,a,b) for (int i = (int)(a); i < (int)(b); ++ i)
#define frr(i,a,b) for (int i = (int)(a); i >= (int)(b); -- i)
#define fre(i, a) for (auto &i : a)
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) {cerr << "[" << #x << "] = ["; _print(x); }
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7;
const ll MM = (ll)MOD * MOD;
const int base = 1e6;
const int B = 32;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; const int dy8[] = {1, -1, 0, 1, -1, 0, 1, -1};
const int dx4[] = {0, 0, 1, -1}; const int dy4[] = {1, -1, 0, 0};
// code go here
int n, m;
int a[25], b[25];
bool f[20005];
void solve(int tc) {
cin >> n >> m;
fr(i, 1, n)
cin >> a[i];
fr(i, 1, m)
cin >> b[i];
f[0] = 1;
fr(i, 1, m)
frr(j, 20000, 0)
if (j + b[i] <= 20000 && f[j])
f[j+b[i]] = 1;
// cerr << f[5];
cout << ((f[a[1]] == 1)? "YES" : "NO");
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
if (fopen(".in", "r")) {
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
freopen(".log", "w", stderr);
}
else if (fopen(Task".in", "r")) {
freopen(Task".in", "r", stdin);
freopen(Task".out", "w", stdout);
}
int test_case = 1;
// cin >> test_case;
// prepare();
fr(i, 1, test_case) {
solve(i);
// bf();
}
return 0;
}
// try your best !!!
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
bank.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(".log", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | freopen(Task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |