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;
int main() {
int n,m;cin >> n >> m;
vector<int> v(n);
vector<int> vc(m);
for (int i = 0;i < n;i++)cin >> v[i];
for (int i = 0;i < n;i++)cin >> vc[i];
vector<int> dzaxot(1 << m, -1);
vector<int> mardik(1 << m, -1);
dzaxot[0] = 0;
mardik[0] = 0;
for (int s = 0; s < (1 << m); s++){
for (int last = 0; last < m; last++) {
if ((s & (1 << last)) == 0)continue;
int prev = s & ~(1 << last);
if (mardik[prev] == -1)continue;
int tiv = dzaxot[prev] + vc[last];
int cel = v[mardik[prev]];
if (tiv < cel) {
mardik[s] = mardik[prev];
dzaxot[s] = tiv;
}
else if (tiv == cel) {
mardik[s] = mardik[prev] + 1;
dzaxot[s] = 0;
}
}
if (mardik[s] == n) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
# | 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... |