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