# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550760 | Karnis_052 | Bank (IZhO14_bank) | C++17 | 64 ms | 34052 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.
// Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int>PI;
typedef pair<ll, ll > PL;
typedef vector<int>VI;
typedef vector<ll>VL;
#define FF first
#define SS second
const int mod = 1e9 + 7;
const int INF = 1e9;
const int N = 20;
ll dp[(1 << N) + 5];
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
int a[n], b[m];
multiset<int, greater<int>>st;
for (int i = 0; i < n; i++)cin >> a[i];
for (int i = 0; i < m; i++)
{
cin >> b[i];
st.insert(b[i]);
}
sort(b, b + m); reverse(b, b + m);
dp[0] = 1;
for (int mask = 0; mask < (1 << n); mask++)
{
if (!dp[mask]) continue;
for (int i = 0; i < n; i++)
{
if ((mask >> i) & 1)continue;
int sum = a[i];
for (int j = 0; j < m; j++)
{
if (sum >= b[j]) sum -= b[j], b[j] = 0;
}
if (sum == 0)
dp[mask | (1 << i)] = 1;
}
}
if (dp[(1 << n) - 1])
cout << "YES" << endl;
else cout << "NO" << endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
return 0;
}
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... |