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 <iostream>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
const int mxN = 20;
const int mod = 998244353;
const int mxlogN = 20;
const int mxK = 26;
int a[mxN];
int b[mxN];
int leftover[1<<mxN];
int people[1<<mxN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("bank.in", "r",stdin);
//freopen("bank.out", "w",stdout);
int n, m; cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < m; i++) cin >> b[i];
for(int i = 0; i < (1<<m); i++)
{
people[i] = -1;
}
people[0] = 0;
leftover[0] = 0;
for(int i = 0; i < (1<<m); i++)
{
for(int j = 0; j < m; j++)
{
if(i&(1<<j))
{
int mask = i^(1<<j);
if(people[mask]==-1)continue;
int covered = people[mask];
int lef = leftover[mask];
if(b[j]+lef < a[covered])
{
people[i] = people[mask];
leftover[i] = lef+b[j];
}
else if(b[j]+lef == a[covered])
{
people[i] = people[mask]+1;
leftover[i] = 0;
}
}
}
if(people[i]==n)
{
cout << "YES\n";
return 0;
}
}
cout << "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... |