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 pb push_back
using namespace std;
const int N = 3e5 + 5;
int n,m,a[N],b[N],sum,fix[N];
vector <int> v[N],v1,v2;
int msk,msk1;
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m;
for (int i = 1; i <= n; i++) {
cin>>a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= m ;i++) {
cin>>b[i];
}
sort(b + 1, b + m + 1);
for (int i = 1; i < (1<<m); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if ((1<<j) & i) sum += b[j + 1];
}
if (sum <= 1000) v[sum].pb(i);
}
v1.pb(0);
for (int i = 1; i <= n; i++) {
v2.clear();
for (int j = 0; j < v[a[i]].size(); j++) { msk = v[a[i]][j];
for (int j1 = 0; j1 < v1.size(); j1++) { msk1 = v1[j1];
if (!(msk & msk1) && !fix[msk | msk1]) v2.pb(msk|msk1);
}
}
for (int i = 0; i < v2.size(); i++) {
fix[v2[i]] = 0;
}
v1 = v2;
}
if (v1.size()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
Compilation message (stderr)
bank.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
11 | main() {
| ^~~~
bank.cpp: In function 'int main()':
bank.cpp:32:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j = 0; j < v[a[i]].size(); j++) { msk = v[a[i]][j];
| ~~^~~~~~~~~~~~~~~~
bank.cpp:33:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int j1 = 0; j1 < v1.size(); j1++) { msk1 = v1[j1];
| ~~~^~~~~~~~~~~
bank.cpp:37:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < v2.size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |