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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m;
vi banknotes, salary;
bool dp[2][(1<<20)];
bool check_bit(int n, int bit){
int ok = n & (1 << bit);
if(ok) return true;
return false;
}
int set_bit(int n, int b){
return (n | (1 << b));
}
int main(){
cin>>n>>m;
banknotes.resize(m);
salary.resize(n);
for(int i = 0; i < n; i++) cin>>salary[i];
for(int i = 0; i < m; i++) cin>>banknotes[i];
sort(salary.begin(), salary.end());
if(n == 1){
bool can[m][1001];
memset(can, false, sizeof can);
can[0][0] = can[0][banknotes[0]] = true;
for(int i = 1; i < m; i++){
for(int j = 0; j <= 1000; j++){
can[i][j] |= can[i-1][j];
if(j >= banknotes[i])
can[i][j] |= can[i-1][j-banknotes[i]];
}
}
if(can[m-1][salary[0]]) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
else
cout<<"NO"<<endl; //TODO
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... |