#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "bank"
using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, N = 20;
void add(int &a, int b)
{
a += b;
if(a>=MOD)
a-=MOD;
if(a<0)
a += MOD;
}
int modulo(int x)
{
if(x<=1)
return 1;
return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}
int mul(int a, int b)
{
return (1ll *a%MOD * b%MOD) % MOD;
}
int n, m;
int a[N+3];
int b[N+3];
int dp[2][(1 << N) + 3];
int pyd[(1 << N)+3];
int pre[(1 << N) + 3];
void inp(void)
{
cin >> n >> m;
FOR(i, 0, n - 1) cin >> a[i];
FOR(i, 0, m - 1) cin >> b[i];
}
void solve(void)
{
memset(pyd, -1, sizeof(pyd));
//memset(pyd, -1, sizeof(pyd));
pyd[0] = 0;
bool ok = false;
FOR(msk, 0, (1 << m) -1)
{
FOR(i, 0, m - 1)
{
if( (msk >> i & 1) == 0) continue;
int prev = (msk ^ (1 << i));
if(pyd[prev] == -1) continue;
int cur = pre[prev] + b[i];
int cost = a[ pyd[prev] ];
if(cur < cost)
{
pre[msk] = cur;
pyd[msk] = pyd[prev];
}
else if(cur == cost)
{
pre[msk] = 0;
pyd[msk] = pyd[prev] + 1;
}
ok |= (pyd[msk] == n);
}
}
if(ok) cout << "YES";
else cout << "NO";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(data".inp", "r"))
{
freopen(data".inp","r",stdin);
freopen(data".out","w",stdout);
}
inp();
solve();
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
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(data".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | freopen(data".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... |