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 ll long long
#define arr array
#define vec vector
#define sz(a) ((int)(a).size())
void B() {
/*
Problem B: Bank
Subtask 1: n = 1, Normal knapsack, 1000
Subtask 2: M <= 10
*/
int N, M;
cin >> N >> M;
int a[N];
int b[M];
for(int i = 0; i < N; i++) {
cin >> a[i];
}
for(int i = 0; i < M; i++) {
cin >> b[i];
}
bool ok = 0;
do {
int x = 0;
ll s = 0;
for(int i = 0; i < M; i++) {
if(s + b[i] > a[x]) {
break;
}
s += b[i];
if(s + b[i] == a[x]) {
x++;
s = 0;
}
if(x == N) {
ok = 1;
break;
}
}
} while(next_permutation(b, b + M));
cout << (ok ? "YES" : "NO") << endl;
}
int main() {
B();
}
# | 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... |