이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long        ll;
typedef pair<int, int>   ii;
typedef vector<ii>      vii;
typedef vector<int>      vi;
#define INF 2000000000
#define MOD 1000000007
#define loop(x,n) for(int x = 0; x < n; ++x)
#define iloop(x,a,n) for(int x=a; x<n; ++x)
#define sloop(e,s) for(auto&& e : s)
#define itloop(it,m) for(auto&& it = m.begin(); it!=m.end(); ++it)
#define F first
#define S second
#define PB push_back
#define MP make_pair
// num_paid (inc. current), left_to_pay; num=-1 if impossible
ii DP[1<<20];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    int salaries[N], notes[M];
    loop(i,N) {
        cin >> salaries[i];
    }
    loop(i,M) {
        cin >> notes[i];
    }
    bool solved = false;
    loop(bm,1<<M) {
        bool works = false;
        if (!bm) {
            DP[bm] = MP(0,salaries[0]);
            continue;
        }
        loop(ind,M) {
            if (bm&1<<ind) {
                int prev = bm^1<<ind;
                if (DP[prev].S==0) {
                    if (salaries[DP[prev].F+1]>=notes[ind]) {
                        DP[bm] = MP(DP[prev].F+1,salaries[DP[prev].F+1]-notes[ind]);
                    } else {continue;}
                }
                if (DP[prev].F<0 || notes[ind]>DP[prev].S) continue;
                DP[bm] = DP[prev];
                DP[bm].S -= notes[ind];
                works = true;
            }
        }
        if (DP[bm] == MP(N-1,0)) {
            solved = true;
            cout << "YES";
            break;
        }
        if (!works) {
            DP[bm] = MP(-1,-1);
        }
    }
    if (!solved) 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... |