//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");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |