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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define pb push_back
#define eb emplace_back
#define pu push
#define ins insert
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ff(x,a,b,c) for (auto x=a;x<=b;x+=c)
#define fd(x,a,b,c) for (auto x=a;x>=b;x-=c)
#define int ll
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
void solve()
{
int n,m;
cin>>n>>m;
vector<int> a(n),b(m);
for (int i=0;i<n;i++) cin>>a[i];
for (int j=0;j<m;j++) cin>>b[j];
vector<pair<int,int>> dp((1<<m),{0,0});
bool check[1<<m] {false}; check[0] = true;
for (int mask=0;mask<(1<<m);mask++)
{
for (int i=0;i<m;i++)
{
if (mask & (1<<i) && check[mask ^ (1<<i)])
{
int nmask = mask ^ (1<<i);
int cur = dp[nmask].second+b[i];
if (cur==a[dp[nmask].first]) dp[mask] = {dp[nmask].first+1,0}, check[mask] = true;
else if (cur<a[dp[nmask].first]) dp[mask] = {dp[nmask].first,cur},check[mask] = true;
}
}
if (dp[mask].first==n)
{
cout<<"YES"; return;
}
}
cout<<"NO";
}
signed main()
{
bruh
int t = 1;
//cin>>t;
while (t--)
{
solve();
//cout<<"\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... |