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;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N = 27;
const int oo = 1e18;
const int mod = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int a[N], b[N], n, m;
bool f;
void sol (int i, int k) {
if (i > n) {
f = 1; return;
} if (k > m) return;
if (a[i] < b[k]) return;
if (a[i] == b[k]) {
sol (i + 1, k + 1);
}
else {
a[i] -= b[k];
sol (i, k + 1);
a[i] += b[k];
sol (i, k + 1);
}
return;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
sort (a + 1, a + n + 1);
sort (b + 1, b + m + 1);
sol (1, 1);
if (f) cout << "YES\n";
else cout << "NO\n";
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... |