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 fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
struct P{
ll x, y;
};
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
const int MAXN = 1<<20;
int dp[MAXN], r[MAXN];
signed main(){
fastio;
memset(dp, -1, sizeof(dp));
int n, m;
cin >> n >> m;
vector<int> pay (n), notes (m);
for (auto &a: pay) cin >> a;
for (auto &a: notes) cin >> a;
bool ans=false;
for (int i=0; i<n; i++){
for (int mask=1; mask<(1<<m); mask++){
int p=-2;
int c=-1;
for (int j=0; j<m; j++){
if (mask & (1 << j)){
if (dp[mask ^ (1 << j)] > p){
p = dp[mask ^ (1 << j)];
c = j;
}
}
}
int d = mask ^ (1 << c);
int v = r[d] + notes[c];
if (dp[d] == i) dp[mask] = i, r[mask] = v;
else if (dp[d] == i-1){
if (v == pay[i]) dp[mask] = i, r[mask] = 0;
else dp[mask] = i-1, r[mask] = v;
}
if (dp[mask] == n-1) ans = true;
}
}
cout << (ans? "YES" : "NO") << '\n';
}
# | 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... |