# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
328558 | Killer2501 | Bank (IZhO14_bank) | C++14 | 1 ms | 364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "guard"
using namespace std;
const int N = 25;
const ll mod = 1e9 + 7;
ll n, m, t, k, a[N], tong, ans, u, v, b[N], pos[N], d[N], dp[(1<<21)][21];
priority_queue< ll, vector<ll>, greater<ll> > pq;
ll c[N];
struct dang
{
ll lc, rc, val, num;
}st[N];
vector<ll> adj[N], kq;
vector<pll> w;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = (total * k) % mod;
k = (k * k) % mod;
}
return total;
}
string s;
void sol()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)cin >> a[i];
for(int i = 1; i <= m; i ++)cin >> b[i];
sort(b+1, b+1+m);
dp[0][0] = 1;
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < (1<<m); j ++)
{
if(dp[i][j] == 0)continue;
t = j;
k = a[i+1];
for(int l = m-1; l >= 0; l --)
{
if((j >> l) & 1)continue;
if(b[l+1] <= k)
{
k -= b[l+1];
t = (t | (1<<l));
}
}
if(k == 0)
{
dp[i+1][t] = 1;
if(i+1 == n)
{
cout << "YES";
return;
}
}
}
}
cout << "NO";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
8
+3
+3
+3
+3
*/
Compilation message (stderr)
# | 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... |