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>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
void solve(){
int n,m,k,q;
cin>>n>>m;
vector<int>a(n),b(m);
for(auto &to:a)cin>>to;
for(auto &to:b)cin>>to;
vector<int>cnt((1<<m),-1);
vector<int>left((1<<m),-1);
cnt[0] = 0;
left[0] = 0;
for(int mask = 0;mask<(1<<m);mask++){
for(int i = 0;i<m;i++){
if(((mask>>i)&1)==0)continue;
int last = mask & ~(1<<i);
if(cnt[last]==-1)continue;
int cont = left[last] + b[i];
int ind = cnt[last];
if(cont == a[ind]){
left[mask] = 0;
cnt[mask] = ind + 1;
}
else if(cont < a[ind]){
left[mask] = cont;
cnt[mask] = ind;
}
}
if(cnt[mask]==n){
cout<<"YES\n";
return;
}
}
cout<<"NO\n";
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt;
while(tt--)solve();
}
Compilation message (stderr)
bank.cpp: In function 'void solve()':
bank.cpp:33:10: warning: unused variable 'k' [-Wunused-variable]
33 | int n,m,k,q;
| ^
bank.cpp:33:12: warning: unused variable 'q' [-Wunused-variable]
33 | int n,m,k,q;
| ^
# | 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... |