This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//BTTHS
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
ifstream fin("file.in");
ofstream fout("file.out");
int n, m, v[29], d[29], f[20009], sm[20009];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> v[i], v[i]+=v[i-1], f[v[i]] = v[i];
int x = n+1;
for (int i = v[n]; i >= 0; i--)
(f[i] == 0 ? f[i] = v[x] : f[i] = v[--x]);
for (int i = 0; i < m; i++)
cin >> d[i];
// for(int i = 0; i <= v[n]; i++)
// cout << f[i] << " ";
sort(d,d+m);
sm[0] = 1;
for (int i = 0; i < m; i++)
{
for (int h = v[n]; h >= 0; h--)
{
if (sm[h])
{
if ((f[h] == f[d[i]] && (f[h+d[i]] == f[h] || f[h+d[i]-1] == f[h])) || (f[h]!=f[h+1] && f[h+d[i]] == f[h+1]))
sm[h+d[i]] = 1;
}
}
}
// for (int i = 0; i <= v[n]; i++)
// {
// cout << i << ": " << sm[i] << "\n";
// }
cout << (sm[v[n]] == 1 ? "YES" : "NO");
}
# | 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... |