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>
//#pragma optimize ("-Ofast")
//#pragma comment (linker, "-STACK 99999999")
#define ld long double
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
//#define int long long
using namespace std;
const int maxn = 25;
int N;
vector <int> worker;
bool f(int nm, vector <int> a)
{
if (nm == N)
{
return true;
}
int n = int(a.size());
int sum = worker[nm];
bool flag = false;
for(int i = 0; i < (1 << n) && !flag; i++)
{
int val = 0;
for(int j = 0; j < n; j++)
{
if ((i & (1 << j)) > 0)
{
val += a[j];
}
}
if (sum == val)
{
vector <int> vc;
for(int j = 0; j < n; j++)
{
if ((i & (1 << j)) == 0)
{
vc.pb(a[j]);
}
}
flag = f(nm + 1, vc);
}
}
return flag;
}
int32_t main()
{
#ifdef LOCAL
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m;
cin >> N >> m;
worker.assign(N, 0);
for(int i = 0; i < N; i++)
{
cin >> worker[i];
}
vector <int> a(m);
for(int i = 0; i < m; i++)
{
cin >> a[i];
}
srand(time(0));
random_shuffle(a.begin(), a.end());
random_shuffle(worker.begin(), worker.end());
if (f(0, a))
{
cout << "YES";
}
else
{
cout << "NO";
}
return 0;
}
# | 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... |