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 faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FOD(i,a,b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define lcm(a,b) (a*b)/__gcd(a,b)
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define iv pair<pair<int,int>,pair<int,int>>
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 20;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const int dxx[] = {-1,-1,0,1,1,1,0,-1};
const int dyy[] = {0,1,1,1,0,-1,-1,-1};
int n, m;
ii dp[(1 << N) + 105];
int a[N], b[N];
void solve()
{
for(int mask = 0; mask < (1 << m); mask++)
dp[mask] = {-1,-1};
dp[0] = {0,0};
for(int mask = 0; mask < (1 << m); mask++)
{
for(int i = 0; i < m; i++)
{
if((mask >> i) & 1 && dp[mask^(1<<i)].fi != -1)
{
int submask = mask ^ (1 << i);
int cur = dp[submask].se + b[i];
int tar = a[dp[submask].fi];
if(tar > cur)
dp[mask] = {dp[submask].fi, cur};
else if(tar == cur)
dp[mask] = {dp[submask].fi + 1, 0};
}
}
if(dp[mask].fi == n)
{
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
void input()
{
//freopen("TEST.INP", "r", stdin);
//freopen("TEST.OUT", "w", stdout);
cin >> n >> m;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < m; i++)
cin >> b[i];
}
signed main()
{
faster
input();
solve();
}
# | 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... |