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;
const int N = 1e3+5;
vector<int> v,a,b;
int st[N] = {0},n,m;
bool check(int k,int s)
{
if(s < 0)return 0;
if(s == 0)
{
if(k == a.size())return 1;
else return check(k+1,a[k+1]);
}
for(int i = 0;i < v.size();i++)
{
if(st[i])continue;
st[i] = 1;
if(check(k,s-v[i]))return 1;
st[i] = 0;
}
return 0;
}
bool sum(int s,int k)
{
if(s < 0)return 0;
if(s == 0)return check(0,a[0]);
for(int i = k;i < m;i++)
{
if(i > k && b[i] == b[i-1])continue;
v.push_back(b[i]);
if(sum(s-b[i],i+1))return 1;
v.pop_back();
}
return 0;
}
int main()
{
cin>>n>>m;
a.resize(n);
b.resize(m);
for(int i = 0;i < n;i++)cin>>a[i];
for(int i = 0;i < m;i++)cin>>b[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
a.push_back(0);
int s = 0;
for(int i = 0;i < n;i++)s += a[i];
if(sum(s,0))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'bool check(int, int)':
bank.cpp:14:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | if(k == a.size())return 1;
| ~~^~~~~~~~~~~
bank.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i = 0;i < v.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... |