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>
using namespace std;
///define-zone
#define task "test"
#define vec vector
#define priq priority_queue
#define pf push_front
#define pb push_back
#define popb pop_back
#define popf pop_front
#define SZ(a) a.begin(), a.end()
#define SZZ(a, begin, end) a + begin, a + begin + end
#define fi first
#define se second
#define BIT(n) (1 << n)
///typedef-zone
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef double db;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
///code-mau
template <class val>
inline val gcd(val a, val b) { return (a ? gcd(b % a, a) : b); }
template <class val>
inline val fmul(val a, val b, val m)
{
if (!b)
return 0;
if (!(b - 1))
return a;
if (b % 2)
return (fmul(a, b / 2, m) * 2 + a) % m;
else
return (fmul(a, b / 2, m) * 2) % m;
}
template <class val>
inline bool getBit(val pos, val mask) { return ((mask >> pos) & 1); }
void fastio()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
void init()
{
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
const int N = int(1e6) + 1;
int dp[(1 << 20)], f[(1 << 20)], a[21], b[21], n, m;
int main()
{
fastio();
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
memset(dp, -1, sizeof(dp));
memset(f, -1, sizeof(f));
dp[0] = f[0] = 0;
for (int mask = 0; mask < BIT(m); mask++)
{
for (int i = 0; i < m; i++)
{
if (!getBit(i, mask))
continue;
int pre = (mask ^ (1 << i));
if (dp[pre] < 0)
continue;
int cur = f[pre] + b[i];
int target = a[dp[pre]];
if (cur < target)
{
dp[mask] = dp[pre];
f[mask] = cur;
}
else if (cur == target)
{
dp[mask] = dp[pre] + 1;
f[mask] = 0;
}
}
if (dp[mask] == n)
{
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void init()':
bank.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(task ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen(task ".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... |