#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 20;
int n, m, dp[1ll << N], remain[1ll << N], arr[N], note[N];
bool set_bit(int mask, int k) { return mask & (1ll << k); }
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < m; i++) cin >> note[i];
for (int mask = 0; mask < (1ll << m); mask++) dp[mask] = -1;
dp[0] = 0;
for (int mask = 0; mask < (1ll << m); mask++) {
for (int i = 0; i < m; i++) {
if (!set_bit(mask, i)) continue;
if (dp[mask] == -1) continue;
int pmask = mask ^ (1ll << i), cur = arr[dp[pmask]];
if (remain[pmask] + note[i] < cur) {
dp[mask] = dp[pmask];
remain[mask] = remain[pmask] + note[i];
} else if (remain[pmask] + note[i] == cur) {
dp[mask] = dp[pmask] + 1;
remain[mask] = 0;
}
}
if (dp[mask] == n - 1) {
cout << "YES" << '\n';
return 0;
}
}
cout << "NO" << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |