This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//------------------------------------\
// ------------------------------ \
// | created by Pham Phuongg | \
// | phamvuphuong2008 | \
// | THPT CHUYEN HA TINH | \
// | HA TINH, VIET NAM | \
// | Bé Phương from TK4-CHT | \
// ------------------------------ \
//------------------------------------\
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
using namespace std;
const int maxn = 20;
int n,m,a[maxn+2],b[maxn+2], dp[maxn][(1<<maxn)+2];
bool isOn(int mask, int i) {
return (mask >> i)&1;
}
int bitSet(int mask, int i) {
return mask^(1<<i);
}
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 = 0; i < m; i++) cin >> b[i];
memset(dp, -1, sizeof dp);
dp[1][0] = 0;
for (int i = 1; i <= n; i++) {
for (int mask = 0; mask < (1 << m); mask++){
if (dp[i][mask] == -1) continue;
for (int j = 0; j < m; j++) {
if (!isOn(mask,j)) {
if (dp[i][mask] + b[j] <= a[i]) {
dp[i][bitSet(mask, j)] = dp[i][mask] + b[j];
}
if (dp[i][mask] == a[i] && b[j] <= a[i+1]) {
dp[i+1][bitSet(mask, j)] = b[j];
}
}
}
}
}
for (int mask = 0; mask < (1 << m); mask++) {
if (dp[n][mask] == a[n]) {
cout << "YES";
return 0;
}
}
cout << "NO";
}
Compilation message (stderr)
bank.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //------------------------------------\
| ^
bank.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | 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... |