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>
#include <math.h>
typedef long long ll;
using namespace std;
ll i, j, t, a, n, m, b, c, d, f, g;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
map <int, int> mpn;
vector <int> vm(m);
for (a=1; a<=n; a++)
{
cin>>c;
mpn[c]=a;
}
for (a=0; a<m; a++)
{
cin>>vm[a];
}
if (n>m)
{
cout<<"NO"<<endl;
return 0;
}
vector <int> vc(m);
set<int> s;
for (a=0; a<m; a++) vc[a]=a;
do
{
s.clear();
int c=0, jem=0;
for (a=0; a<m; a++)
{
jem=jem+vm[vc[a]];
if (mpn[jem]!=0 and !s.count(mpn[jem]))
{
s.insert(mpn[jem]);
c++;
jem=0;
}
}
if (c==n)
{
cout<<"YES"<<endl;
return 0;
}
}
while(next_permutation(vc.begin(), vc.end()));
cout<<"NO"<<endl;
}
/*
1 5
8
4 2 5 1 3
*/
# | 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... |