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>
#define ll long long
#define pb push_back
#define debug(x) cout << #x << " = " << x << " ";
#define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define S second
#define F first
using namespace std;
const int maxn = 21;
int n , m , ar[maxn] , br[maxn] , sum[(1 << maxn)] , dp[(1 << maxn)] , ps[maxn];
int32_t main()
{
fast;
cin >> n >> m;
for(int i = 1 ; i <= n ; i++) cin >> ar[i];
for(int i = 0 ; i < m ; i++) cin >> br[i];
for(int i = 1 ; i < (1 << m) ; i++)
{
for(int j = 0 ; j < m ; j++)
{
if((i >> j) & 1)
{
sum[i] = sum[(i ^ (1 << j))] + br[j];
break;
}
}
}
bool flg = false;
for(int i = 1 ; i <= n ; i++) ps[i] = ps[i - 1] + ar[i];
for(int mask = 1 ; mask < (1 << m) ; mask++)
{
for(int i = 0 ; i < m ; i++)
{
if((mask >> i) & 1)
{
int s = (mask ^ (1 << i));
int tmp = dp[s];
int sum1 = ps[tmp + 1] , sum2 = sum[mask];
if(sum1 == sum2)
tmp++;
dp[mask] = max(dp[mask] , tmp);
}
}
if(dp[mask] == n)
flg = true;
}
cout << (flg ? "YES" : "NO") << endl;
return 0;
}
# | 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... |