이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
#define vi vector<int>
#define ii pair<int, int>
#define pb push_back
#define f first
#define s second
#define all(i) (i).begin(), (i).end()
#define MOD 1000000007
#define endl '\n'
int main() {
int n, m;
cin>>n>>m;
vi salary(n);
vi bank(m);
rep(i, 0, n)
cin>>salary[i];
rep(j, 0, m)
cin>>bank[j];
vi covered(1<<m, -1);
vi leftover(1<<m, -1);
covered[0] = 0;
leftover[0] = 0;
for(int mask = 0; mask < (1<<m); mask++) {
for(int take = 0; take < m; take++) {
if((mask & (1<<take)) == 0) continue;
int prev = mask & ~(1<<take);
if(covered[prev] == -1) continue;
int cur = leftover[prev] + bank[take];
int req = salary[covered[prev]];
if(cur < req) {
covered[mask] = covered[prev];
leftover[mask] = cur;
}
else if(cur == req) {
leftover[mask] = 0;
covered[mask] = covered[prev] + 1;
}
}
if(covered[mask] == n) {
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
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... |