이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<m; i++) cin >> b[i];
    vector<int> peopleCovered((1<<m), -1);
    vector<int> moneyLeft((1<<m), -1);
    peopleCovered[0] = 0;
    moneyLeft[0] = 0;
    for(int mask = 0; mask<(1<<m); mask++){
        for(int i=0; i<m; i++){
            if(mask&(1<<i)){
                int prevMask = mask & ~(1<<i);
                if(peopleCovered[prevMask]==-1) continue;
                int newMoney = moneyLeft[prevMask] + b[i];
                int curTarget = a[peopleCovered[prevMask]];
                if(newMoney < curTarget){
                    peopleCovered[mask] = peopleCovered[prevMask];
                    moneyLeft[mask] = newMoney;
                }
                else if(newMoney == curTarget){
                    peopleCovered[mask] = peopleCovered[prevMask] + 1;
                    moneyLeft[mask] = 0;
                }
            }
        }
        if(peopleCovered[mask]==n){
            cout << "YES" << '\n';
            return 0;
        }
    }
    cout << "NO" << '\n';
}
| # | 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... |