This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//----------vahagng----------//
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.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>;
// Defines
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pii pair<int, int>
#define ppb pop_back
#define pb push_back
#define mii map<int, int>
#define mll map<long long, long long>
#define no_ans cout << -1 << '\n';
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ok cout << "OK\n";
// Constants
const int N = 21, M = 105;
const ll inf = 1e18, mod = 1e9+7;
// Functions
void SetIO(string str = "") {
if (str != "") {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
} else {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
}
void FastIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
ll add(ll a, ll b)
{
return (a + b)%mod;
}
ll mult(ll a, ll b)
{
return (a%mod * b%mod)%mod;
}
ll sub(ll a, ll b)
{
return (a - b + 2*mod)%mod;
}
long long binpower(long long a, long long n) {
if(n == 0) {
return 1;
}
if(n == 1) {
return a;
}
if(n % 2 == 1) {
long long curr = binpower(a, n / 2);
curr = mult(curr, curr);
curr = mult(a, curr);
return curr;
} else {
long long curr = binpower(a, n / 2);
return mult(curr, curr);
}
}
ll power(int a, int b)
{
ll res = 1;
while(b--)
{
res*=a;
}
return res;
}
// const int N = 2e5 + 10;
// pair<int,int>max_dist;
// vector<int>adj[N];
// int dists[N];
// void dfs(int node, int parent, int dist)
// {
// dists[node] = max(dists[node], dist);
// if(dist > max_dist.first)
// {
// max_dist = {dist, node};
// }
// for(auto i: adj[node])
// {
// if(i == parent) continue;
// dfs(i, node, dist + 1);
// }
// }
// pair<int, int> get_farthest_distance(int node)
// {
// max_dist = {-1, -1};
// dfs(node, -1, 0);
// return max_dist;
// }
void precision(int x)
{
cout.setf(ios::fixed | ios::showpoint);
cout.precision(x);
return;
}
ll countSubstring(const string str, const string sub)
{
if (sub.length() == 0) return 0;
ll count = 0;
for(int i = 0; i < str.size() - sub.size() + 1; i++)
{
int okk = 1;
for(int j = i; j < i + sub.size(); j++)
{
if(str[j] != sub[j - i])
{
okk = 0;
break;
}
}
count += okk;
}
return count;
}
ll ceil_division(ll a, ll b)
{
return (a + b - 1) / b;
}
ll max_subarray_sum(vector<ll>& v, int n)
{
ll a = INT64_MIN, b = 0;
for(int i = 0; i < n; i++)
{
b += v[i];
if(b > a)
{
a = b;
}
if(b<0)
{
b = a;
}
}
return a;
}
// Solution
int n, m;
int dp[1<<21];
vector<int>v, b;
vector<int>posible[1001];
void solve()
{
cin >> n >> m;
v.resize(n);
b.resize(m);
for(auto& i : v) cin >> i;
for(auto& i : b) cin >> i;
for(int mask = 1; mask < (1<<m); mask++)
{
int cur = 0;
for(int j = 0; j < m; j++)
{
if(mask & (1<<j))
{
cur+=b[j];
}
}
if(cur <= 1000) posible[cur].push_back(mask);
}
for(int i = 0; i < (1<<m); i++) dp[i] = -1;
dp[0] = 0;
for(int i = 0; i < n; i++)
{
for(int mask = (1<<m) - 1; mask >= 0; mask--)
{
if(dp[mask] == -1) continue;
for(auto j : posible[v[i]])
{
if(!(j&mask))
{
dp[j|mask] = dp[mask] + 1;
if(dp[j|mask] == n)
{
cout << "YES\n";
return;
}
}
}
}
}
cout << "NO\n";
}
void precalc()
{
}
int main()
{
// SetIO("pairup");
FastIO();
precalc();
int test_case = 1;
// cin >> test_case;
while (test_case--)
{
solve();
}
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'long long int countSubstring(std::string, std::string)':
bank.cpp:131:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for(int i = 0; i < str.size() - sub.size() + 1; i++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:134:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
134 | for(int j = i; j < i + sub.size(); j++)
| ~~^~~~~~~~~~~~~~~~
bank.cpp: In function 'void SetIO(std::string)':
bank.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | freopen((str + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen((str + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen("output.txt", "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... |