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;
using ll = long long;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "IZhO14_bank"
void Fi(){
if(fopen(PROB".inp", "r")){
freopen(PROB".inp", "r", stdin);
freopen(PROB".out", "w", stdout);
}
}
const int N = 20;
int n, m;
int a[N + 1], b[N];
int dp[1 << N], lef[1 << N];
int main(){
IOS;
Fi();
cin >> n >> m;
FORU(i, 1, n) cin >> a[i];
FOR(i, 0, m) cin >> b[i];
memset(dp, -1, sizeof(dp));
dp[0] = lef[0] = 0;
FOR(mask, 1, 1 << m){
FOR(j, 0, m) if(mask & (1 << j)){
if(dp[mask ^ (1 << j)] == -1) continue;
int newi = dp[mask ^ (1 << j)] + 1;
int have = lef[mask ^ (1 << j)] + b[j];
if(have < a[newi]){
dp[mask] = newi - 1;
lef[mask] = have;
} else if(have == a[newi]){
dp[mask] = newi;
lef[mask] = 0;
}
}
if(dp[mask] == n){
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'void Fi()':
bank.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(PROB".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(PROB".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |