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 ll long long
#define fi first
#define se second
#define endl '\n'
#define mask(i) (1LL << (i))
#define task "name"
#define ull unsigned long long
using namespace std;
const ll mxN = 220797 + 7;
const ll inf = 1e9 + 277;
const ll mod = 2147483648;
const ll infll = 1e18 + 7;
const ll base = 307;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int a[mxN] , b[mxN] , c[mxN];
int dp1[(1 << 20) + 7];
int dp2[(1 << 20) + 7];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("task.inp" , "r" , stdin);
//freopen("task.out" , "w" , stdout);
int n , m;
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) cin >> a[i];
for(int i = 1 ; i <= m ; i++) cin >> b[i];
memset(dp1 , -1 , sizeof(dp1));
dp1[0] = 0;
dp2[0] = 1;
for(int mask = 0 ; mask < (1 << m) ; mask++) {
for(int last = 0 ; last < m ; last++) {
if(!(mask & (1 << last))) continue;
int pre = mask & ~(1 << last);
if(dp1[pre] == -1) continue;
int cur = dp2[pre];
if(dp1[pre] + b[last + 1] < a[cur]) {
dp1[mask] = dp1[pre] + b[last + 1];
dp2[mask] = dp2[pre];
}
if(dp1[pre] + b[last + 1] == a[cur]) {
dp1[mask] = 0;
dp2[mask] = cur + 1;
if(cur + 1 > n) {
cout << "YES";
return 0;
}
}
}
}
cout << "NO" << endl;
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... |