이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("bank.in", "r", stdin);
// freopen("bank.out", "w", stdout);
int n, m;
cin >> n >> m;
vector<int> people(n), money(m);
for (int i = 0; i < n; i++)
cin >> people[i];
for (int i = 0; i < m; i++)
cin >> money[i];
vector<vector<int> > make(1005), dp(n+1);
for (int b = 0; b < (1<<m); b++) {
int now = 0;
for (int j = 0; j < m; j++)
if (b&(1<<j)) now += money[j];
if (now <= 1000)
make[now].pb(b);
}
dp[0].pb(0);
for (int i = 0; i < n; i++) {
for (int state : dp[i]) {
for (int b : make[people[i]]) {
if ((b^state) < (b+state)) continue;
dp[i+1].pb(b^state);
}
}
}
if (dp[n].empty())
cout << "NO\n";
else
cout << "YES\n";
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# | 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... |