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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pdouble(x) fixed<<setprecision(20)<<x
#define inf 1e9
#define inff 1e18
#define vec vector
#define pii pair<int,int>
#define pll pair<long long,long long>
#define maxv(a) *max_element(a.begin(), a.end())
#define minv(a) *min_element(a.begin(), a.end())
#define pb push_back
#define ff first
#define ub upper_bound
#define lb lower_bound
#define ss second
#define YY cout << "YES" << endl
#define NN cout << "NO" << endl
#define C(x) cout << x << endl
#define f(i, a, b) for (int i = a; i < b; i++)
#define rf(i, a, b) for (int i = a - 1; i >= b; i--)
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define google(i, x) cout << "Case #" << i << ": " << x << endl
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
const ll M = 1e9+7;
ll gcd(ll a, ll b) { while (b) {a %= b; swap(a,b);} return a; }
ll lcm(ll a, ll b) { ll g=gcd(a,b); ll res=a*(b/g); return res; }
ll extended_gcd(ll a, ll b, ll &x, ll &y) { if (b==0) { x=1; y=0; return a; } ll x1,y1; ll g=extended_gcd(b,a%b,x1,y1); x=y1; y=x1-y1*(a/b); return g; }
ll binExp(ll a, ll b, ll m=M) { a = a % m; ll res = 1; while (b) { if (b&1) { res=(res * a) % m; } a=(a * a) % m; b>>=1; } return res; }
ll mod_inv(ll a, ll m=M) { a = a % m; return binExp(a,m-2,m); } // only for prime m
ll mod_add(ll a, ll b, ll m=M) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; }
ll mod_sub(ll a, ll b, ll m=M) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m=M) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; }
ll mod_div(ll a, ll b, ll m=M) { a = a % m; ll binv = mod_inv(b,m); return (((a*binv)%m)+m)%m; }
int test;
void print(auto &a)
{
for(auto it:a)
{
cout<<it<<" ";
}
cout<<endl;
}
/**************************** C..O..D..E ****************************/
const int N = 1e5+3;
void solve()
{
int n,m; cin>>n>>m;
vec<int> a(n),b(m);
f(i,0,n) cin>>a[i];
f(i,0,m) cin>>b[i];
vec<pii> dp(1<<m);
dp[0] = {0,0};
int f=0;
for(int s = 0; s < (1<<m); s++)
{
if(dp[s].ff == n)
{
f=1;
break;
}
for(int j = 0; j < m; j++)
{
if(s&(1<<j)) continue;
pii newState;
if(a[dp[s].ff] == dp[s].ss+b[j])
{
newState = {dp[s].ff+1, 0};
}
else
{
newState = {dp[s].ff, dp[s].ss+b[j]};
}
dp[s|(1<<j)] = max(dp[s|(1<<j)], newState);
}
}
if(f) YY;
else NN;
}
int main()
{
fast_io;
// fun();
int t = 1;
// cin>>t;
test = 1;
while(t--)
{
solve();
test++;
}
return 0;
}
Compilation message (stderr)
bank.cpp:47:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
47 | void print(auto &a)
| ^~~~
# | 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... |