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>
#include <ext/pb_ds/assoc_container.hpp>
#define fr first
#define se second
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define IN(i,l,r) (l<i&&i<r)
#define pb push_back
#define ones __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
template <class T>
using OSTree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef long long ll;
const int U = 20;
int main(){
cin.tie(0)->sync_with_stdio(false);
int n,m; cin >> n >> m;
vi a(n), b(m);
rep(i,0,n) cin >> a[i];
rep(i,0,m) cin >> b[i];
vll dp(1<<U,-1), remcash(1<<U,-1);
dp[0] = 0;
remcash[0] = 0;
bool flag = false;
rep(i,1,1<<m){
rep(j,0,m){
if(i&(1<<j) == 0) continue;
int z = i ^ (1<<j);
if(dp[z] < 0) continue;
if(remcash[z] + b[j] < a[dp[z]]){
dp[i] = dp[z];
remcash[i] = remcash[z] + b[j];
}else if(remcash[z] + b[j] == a[dp[z]]){
dp[i] = dp[z] + 1;
remcash[i] = 0;
}
}
if(dp[i] == n){
flag = true; break;
}
}
cout << (flag ? "YES" : "NO") << '\n';
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:34:25: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
34 | if(i&(1<<j) == 0) continue;
| ~~~~~~~^~~~
# | 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... |