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 pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e6 + 1e5 + 10;
const ll mod = 998244353;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
int a[N], b[N], n, m;
int dp[N], last[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
//freopen("bank.in", "r", stdin);
//freopen("bank.out", "w", stdout);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
bool can = false;
for(int mask = 0; mask < (1 << m); mask++){
dp[mask] = -1;
}
dp[0] = 0;
for(int mask = 0; mask < (1 << m); mask++){
for(int dig = 0; dig < m; dig++){
if((mask & (1 << dig)) > 0){
int nw = mask ^ (1 << dig);
int mx = dp[nw], rest = last[nw];
if(dp[nw] == -1) continue;
if(last[nw] + b[dig] == a[dp[nw]]){
mx++;
rest = 0;
} else rest += b[dig];
if(mx >= dp[mask]){
dp[mask] = mx;
last[mask] = rest;
}
}
}
if(dp[mask] == n){
can = true;
break;
}
}
if(can) cout << "YES\n";
else cout << "NO\n";
return 0;
}
# | 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... |