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;
bool check(vector<int> x,vector<int> y,int s,int k,vector<int> left,vector<int> right)
{
if(s < 0)return 0;
if(s == 0)
{
if(x.size() == 1)return 1;
int suma = 0;
for(int i = 0;i < x.size()/2;i++)suma += x[i];
vector<int> tp;
for(int i = 0;i < x.size()/2;i++)tp.push_back(x[i]);
if(check(tp,left,suma,0,vector<int>(),vector<int>()))
{
tp.clear();
suma = 0;
for(int i = x.size()/2;i < x.size();i++)suma += x[i];
for(int i = x.size()/2;i < x.size();i++)tp.push_back(x[i]);
if(check(tp,right,suma,0,vector<int>(),vector<int>()))return 1;
}
return 0;
}
for(int i = k;i < y.size();i++)
{
if(i > k && y[i] == y[i-1]){right.push_back(y[i]);continue;}
left.push_back(y[i]);
if(check(x,y,s-y[i],i+1,left,right))return 1;
left.pop_back();
right.push_back(y[i]);
}
return 0;
}
int n,m;
vector<int> v,a,b;
bool sum(int s,int k)
{
if(s < 0)return 0;
if(s == 0)
{
int suma = 0;
for(int i = 0;i < a.size()/2;i++)suma += a[i];
if(check(a,v,suma,0,vector<int>(),vector<int>()))return 1;
return 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(std::vector<int>, std::vector<int>, int, int, std::vector<int>, std::vector<int>)':
bank.cpp:13:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i = 0;i < x.size()/2;i++)suma += x[i];
| ~~^~~~~~~~~~~~
bank.cpp:15:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0;i < x.size()/2;i++)tp.push_back(x[i]);
| ~~^~~~~~~~~~~~
bank.cpp:20:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = x.size()/2;i < x.size();i++)suma += x[i];
| ~~^~~~~~~~~~
bank.cpp:21:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = x.size()/2;i < x.size();i++)tp.push_back(x[i]);
| ~~^~~~~~~~~~
bank.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = k;i < y.size();i++)
| ~~^~~~~~~~~~
bank.cpp: In function 'bool sum(int, int)':
bank.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < a.size()/2;i++)suma += a[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... |