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;
typedef long long ll;
#define _io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define MAX 1e9
int dp[30][30];
vi salarios(100); //sums
vi notas(100); //set
int solve(int n,int sum){
if(sum==0) return 1;
if(n<=0) return 0;
if(dp[n-1][sum]!=-1) return dp[n-1][sum];
if(notas[n-1] > sum){
return dp[n-1][sum] = solve(n-1,sum);
}
else{
return dp[n - 1][sum] = solve(n - 1, sum) || solve(n - 1, sum - notas[n - 1]);
}
}
int main(){ _io
int n,m; cin >> n >> m;
for(int i=0;i<n;i++) cin >> salarios[i]; // vet de sums
for(int i=0;i<m;i++) cin >> notas[i]; //
bool ok = true;
for(int i=0;i<n;i++){
//cout << "vai\n";
memset(dp,-1,sizeof(dp));
if(!solve(m,salarios[i])){
ok=false; break;
}
}
cout << (ok?"YES\n":"NO\n");
}
# | 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... |