This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Nếu thế giới có 8 tỷ người yêu em, anh là một trong số họ
//Nếu thế giới có 1 người yêu em, thì anh chính là người đó
//Nếu thế giới không còn ai yêu em, thì có nghĩa là anh đã chết </3
//dyk19b1
#include <bits/stdc++.h>
// #define int long long
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define BIT(mask,i) ((mask >> i) & 1ll )
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ii pair <int,int>
using namespace std;
#define read doc()
int doc () {bool minus = false;int result = 0;char ch;ch = getchar();while (true) {if (ch == '-') break;if (ch >= '0' && ch <= '9') break;ch = getchar();}if (ch == '-') minus = true; else result = ch-'0';while (true) {ch = getchar();if (ch < '0' || ch > '9') break;result = result*10 + (ch - '0');}if (minus)return -result;else return result;}
template<class X, class Y>bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;}
template<class X, class Y>bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;}
const long long oo = 1e18;
const int N = 1e6+5;
const int MOD = 1e9+7;
// int dp[21][(1 << 20)-1];
vector <int> M[1001];
int a[25],b[25];
int n,m;
int solve(int i,int mask)
{
// cout << i << " " << mask << endl;
if (i > n) return 1;
int cur = 0;
for(auto v:M[a[i]])
{
// cout << (mask & v) ;
if ((mask & v )== 0)
{
// cout << 1;
cur = max(cur,(solve(i+1,mask | v)));
}
}
return cur;
}
void TnKh()
{
cin >> n >> m;
FOR(i,1,n) cin >> a[i];
FOR(i,1,m) cin >> b[i];
FOR(mask,1,(1 << m)-1)
{
int ans = 0;
FOR(i,0,m-1) if (BIT(mask,i)) ans += a[i+1];
if (ans <= 1000) M[ans].push_back(mask);
}
// for(auto x:M[8]) cout <<x << " ";
cout <<(solve(1,0) ? "YES" : "NO");
return;
}
#define TASK "bank"
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
freopen(TASK".in","r",stdin);freopen(TASK".out","w",stdout);
int Dyk19b1 = 1;
// cin >> Dyk19b1;
while (Dyk19b1--) TnKh();
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(TASK".in","r",stdin);freopen(TASK".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:62:41: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(TASK".in","r",stdin);freopen(TASK".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... |