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, vis[N];
void sol (int k) {
if (k > n) {
f = 1; return;
}
for (int i = 1; i <= m; i++) {
if (!vis[i]) {
if (b[i] <= a[k]) {
a[k] -= b[i];
vis[i] = 1;
if (a[k] == 0) sol (k + 1);
else sol (k);
a[k] += b[i];
vis[i] = 0;
}
}
}
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);
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... |