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 f first
#define s second
#define pb push_back
#define int long long
#define N 2000006
#define pii pair<int, int>
#define piii pair<int, pii>
using namespace std;
int n, m, i, j, a[25], c[25], r[N], l, p[N], b;
main()
{
std::ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(i = 0; i < n; i++)
cin >> a[i];
for(i = 0; i < m; i++)
cin >> c[i];
for(b = 0; b < (1 << m); b++)
p[b] = r[b] = -1;
p[0] = r[0] = 0;
for(b = 0; b < (1 << m); b++)
{
for(i = 0; i < m; i++)
if(b & (1 << i))
{
l = b ^ (1 << i);
if(p[l] == -1) continue;
if(r[l] + c[i] == a[p[l]]) p[b] = p[l] + 1, r[b] = 0;
else if(r[l] + c[i] < a[p[l]]) p[b] = p[l], r[b] = r[l] + c[i];
}
if(p[b] == n) { cout << "YES\n"; return 0; }
}
cout << "NO\n";
}
Compilation message (stderr)
bank.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main()
| ^~~~
# | 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... |