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>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 20 , mod = 1e9 + 7; // !
int t, a[N], b[N];
int dp[(1 << N)];
main(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i], a[i] += a[i - 1];
for(int i = 0; i < m; i++) cin >> b[i];
for(int i = 0; i < (1 << m); i++) {
int cur = 0;
for(int j = 0; j < m; j++) if((1 << j) & i) cur += b[j];
for(int j = 0; j < m; j++) {
if((1 << j) & i) {
dp[i] = max(dp[i], dp[i ^ (1 << j)] + (a[dp[i ^ (1 << j)]] == cur));
}
}
// cout << i << " __ " << a[dp[i] + 1] << endl;
}
cout << (dp[(1 << m) - 1] == n ? "YES" : "NO");
}
Compilation message (stderr)
bank.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^~~~
# | 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... |