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 boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N=2e5+5;
const int inf=1e9;
const int mod=1e9+7;
const int N1=1e6+1;
vector<int>v;
vector<int>v1;
struct edge{
int v,time;
};
signed main(){
// freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
boost;
int n,m;
cin>>n>>m;
v.push_back(0);
int sum=0,sum1=0;
for(int i=0;i<n;i++){
int x;
cin>>x;
v.push_back(x);
sum+=x;
}
for(int i=0;i<m;i++){
int x;
cin>>x;
sum1+=x;
v1.push_back(x);
}
if(n>m||sum>sum1){
cout<<"NO\n";
return 0;
}
if(n==1){
for(int i=0;i<(1<<m);i++){
int cnt=0;
for(int j=0;j<m;j++){
if(1&(i>>j)){
cnt+=v1[j];
}
}
if(cnt==v[1]){
cout<<"YES";
return 0;
}
}
cout<<"NO";
return 0;
}
if(n==m){
sort(v.begin(),v.end());
sort(v1.begin(),v1.end());
int cnt=0;
for(int i=1;i<=n;i++){
if(v[i]!=v1[i-1]){
cnt=1;
}
}
if(cnt==0){
cout<<"YES";
}else{
cout<<"NO";
}
return 0;
}
sort(v1.begin(),v1.end());
do{
int j=1;
int cnt=0;
for(int i=0;i<v1.size();i++){
cnt+=v1[i];
if(cnt==v[j]&&j<=n){
j++;
cnt=0;
}
}
if(j==n+1){
cout<<"YES\n";
return 0;
}
}while(next_permutation(v1.begin(),v1.end()));
cout<<"NO\n";
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:75:22: 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]
75 | for(int i=0;i<v1.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... |