This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I will instruct you and teach you in the way you should go;
// I will counsel you with my loving eye on you. Psalms 32:8
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) printf(args)
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 20
#define MAXNP 1100000
int n, m;
int a[MAXN], b[MAXN];
ii dp[MAXNP];
int main() {
int _t = 1;
// scanf("%d", &_t);
while (_t--) {
scanf("%d%d", &n, &m);
REP (i, 0, n) {
scanf("%d", &a[i]);
}
REP (i, 0, m) {
scanf("%d", &b[i]);
}
REP (i, 0, 1 << m) {
dp[i] = MP(0, 0);
REP (j, 0, m) {
if (!(i >> j & 1)) {
continue;
}
int k = i ^ (1 << j);
ii res = dp[k];
res.SE += b[j];
if (a[res.FI] == res.SE) {
res.FI++;
res.SE = 0;
}
mxto(dp[i], res);
}
}
if (dp[(1 << m) - 1].FI == n) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:50:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
bank.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d", &b[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |