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;
#include <ext/pb_ds/assoc_container.hpp>
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
typedef long long ll;
#define pb push_back
#define se second
#define fi first
#define all(x) x.begin(),x.end()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<ll> vll;
#define mid (l+r)/2
#define alt cout<<endl
const int MAXN=25;
const int INF=1e9;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//ifstream cin ("movie.in");
//ofstream cout ("movie.out");
int n,m;
cin>>n>>m;
vii dp (1<<m);
int people[n], money[m];
FOR(i,n){
cin>>people[i];
}
FOR(i,m){
cin>>money[i];
}
dp[0]={0,0};
bool flag=false;
FORE(s,0,(1<<m)){
if(dp[s].fi==n){
flag=true;
break;
}
FOR(j,m){
if(s & (1<<j)) continue;
pii temp;
if(people[dp[s].fi]==dp[s].se+money[j]){
temp={dp[s].fi+1,0};
}
else{
temp={dp[s].fi,dp[s].se+money[j]};
}
dp[s | (1<<j)]=max(dp[s| (1<<j)],temp);
}
}
if(flag) cout<<"YES";
else cout<<"NO";
}
# | 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... |