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 int long long
signed main()
{
int n;
cin >> n;
int m;
cin >>m;
int sal[n];
int note[m];
for(int i=0;i<n;i++)cin >> sal[i];
for(int i=0;i<m;i++)cin >> note[i];
vector<int> covered((1<<m)+1,-1);
vector<int> left((1<<m)+1,-1);
covered[0] = 0;
left[0] = 0;
for(int i=0;i<(1<<m);i++)
{
for(int j=0;j<m;j++)
{
if(i & (1<<j))
{
int prev = i ^ (1<<j);
if(covered[prev] == -1)
continue;
int newamt = left[prev] + note[j];
int target = sal[covered[prev]];
if(newamt < target)
{
covered[i] = covered[prev];
left[i] = newamt;
}
else if(newamt == target)
{
covered[i] = covered[prev] + 1;
left[i] = 0;
}
}
}
if(covered[i] == n)
{
cout << "YES\n";
return 0;
}
}
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... |