이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// barkolorious - 29 November 2024
// in god, do we trust? 
#include <bits/stdc++.h>
using namespace std;
#define FIN(x) freopen(x ".in", "r", stdin)
#define FOUT(x) freopen(x ".out", "w", stdout)
#define int long long
#define pb  push_back
#define fr  first
#define sc  second
#define __  << " " << 
#define check_bit(a, i) (((a) & (1 << (i))) >> (i))
#define flip_bit(a, i)  ((a) ^ (1 << (i)))
const int N = 2e5 + 5;
void solve () {
  int n, m; cin >> n >> m;
  vector<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];
  int E = (1 << m);
  pair<int, int> dp[E];
  dp[0] = {0, 0};
  for (int s = 0; s < E; s++) {
    for (int i = 0; i < m; i++) {
      if (!check_bit(s, i)) continue;
      auto last = dp[flip_bit(s, i)];
      if (last.sc + b[i] == a[last.fr]) { last.fr++; last.sc = 0; }
      else if (last.sc + b[i] < a[last.fr]) { last.sc += b[i]; }
      dp[s] = last;
    }
    if (dp[s].fr == n) {
      cout << "YES" << endl;
      return;
    }
  }
  cout << "NO" << endl;
}
/*
-- Sample 1 --
Input:
Output:
*/
/*
g++ -std=c++17 -O2 -Wall -DLOCAL "C:\Users\LENOVO\Desktop\BARKIN\Genel\Programming\Competitive\Questions\oj.uz\IZhO14\IZhO14_bank.cpp" -o _run
*/
int32_t main () {
  #ifndef LOCAL
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
  #endif
  #ifdef LOCAL
    clock_t __START__ = clock();
    FILE* __FILE_IN__ = FIN("C:/Users/LENOVO/Desktop/BARKIN/Genel/Programming/Competitive/_run");
    FILE* __FILE_OUT__ = FOUT("C:/Users/LENOVO/Desktop/BARKIN/Genel/Programming/Competitive/_run");
  #endif
  solve();
  #ifdef LOCAL
    fclose(__FILE_IN__);
    fclose(__FILE_OUT__);
    cerr << "Executed in: " << fixed << setprecision(3) << (double) (clock() - __START__) / CLOCKS_PER_SEC << "seconds" << endl;
  #endif
  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... |