이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;
const int N = 20;
const int maxn = 1e5 + 4;
const int INF = 1e9;
int n, m, people[N], banknote[N], people_covered[1 << N], leftover[1 << N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> people[i];
for (int i = 0; i < m; i++) cin >> banknote[i];
memset(people_covered, -1, sizeof people_covered);
memset(leftover, -1, sizeof leftover);
leftover[0] = people_covered[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 (people_covered[prev] == -1) continue;
int new_salary = leftover[prev] + banknote[last];
int cur_salary = people[people_covered[prev]];
if (new_salary < cur_salary)
{
people_covered[s] = people_covered[prev];
leftover[s] = new_salary;
}
else if (new_salary == cur_salary)
{
people_covered[s] = people_covered[prev] + 1;
leftover[s] = 0;
}
}
if (people_covered[s] == n)
{
cout << "YES";
return 0;
}
}
cout << "NO";
}
# | 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... |