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 ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 5e5 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 4e6 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
int n, m, a[22], b[22], covered[1 << 22], leftover[1 << 22];
int main(){
speed;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
memset(covered, -1, sizeof(covered));
memset(leftover, -1, sizeof(leftover));
covered[0] = 0;
leftover[0] = 0;
for(int mask = 0; mask < (1 << m); mask++){
for(int i = 0; i < m; i++){
if((1 << i) & mask == 0)
continue;
int prev = (mask ^ (1 << i));
if(covered[prev] == -1)
continue;
if(leftover[prev] + b[i] < a[covered[prev]]){
covered[mask] = covered[prev];
leftover[mask] = leftover[prev] + b[i];
}else if(leftover[prev] + b[i] == a[covered[prev]]){
covered[mask] = covered[prev] + 1;
leftover[mask] = 0;
}
}
if(covered[mask] == n){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
/*
%I64d
Z
%I64d
*/
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:48:23: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
48 | if((1 << i) & mask == 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... |