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;
vector <int> vn(n);
vector <int> vm(m);
for (a=0; a<n; a++)
{
cin>>vn[a];
}
for (a=0; a<m; a++)
{
cin>>vm[a];
}
if (n>m)
{
cout<<"NO"<<endl;
return 0;
}
vector <int> vc(m);
for (a=0; a<m; a++) vc[a]=a;
do
{
int c=0, jem=0;
for (a=0; a<m; a++)
{
jem=jem+vm[vc[a]];
if (jem==vn[c])
{
jem=0;
c++;
}
if (jem>vn[c])
{
c=0;
break;
}
}
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... |