Submission #741264

#TimeUsernameProblemLanguageResultExecution timeMemory
741264asdfgraceBank (IZhO14_bank)C++17
100 / 100
139 ms8536 KiB
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) //x
#define A(x) DEBUG(assert(x))
#define PRINT(x) DEBUG(cerr << x)
#define PV(x) DEBUG(cerr << #x << " = " << x << '\n')
#define PV2(x) DEBUG(cerr << #x << " = " << x.first << ',' << x.second << '\n')
#define PAR(x) DEBUG(PRINT(#x << " = { "); for (auto y : x) PRINT(y << ' '); PRINT("}\n");)
#define PAR2(x) DEBUG(PRINT(#x << " = { "); for (auto [y, z] : x) PRINT(y << ',' << z << "  "); PRINT("}\n");)
typedef int64_t i64;
const int INF = 1000000007; //998244353;

struct S {
  int n, m;
  vector<int> a, b;

  void run() {
    cin >> n >> m;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    b.resize(m);
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
    }
    
    vector<int> last(1 << m, 0), left(1 << m, 0);
    for (int i = 0; i < 1 << m; ++i) {
      int option = 0;
      for (int j = 0; j < m; ++j) {
        if (!(i & (1 << j))) continue;
        int prev = i ^ (1 << j);
        if (left[prev] + b[j] == a[last[prev]] && last[prev] + 1 >= last[i]) {
          last[i] = last[prev] + 1;
          left[i] = 0;
          option = 2;
        } else if (left[prev] + b[j] < a[last[prev]] && last[prev] >= last[i]) {
          last[i] = last[prev];
          left[i] = left[prev] + b[j];
          option = 1;
        }
      }
      if (last[i] == n) {
        cout << "YES\n";
        return;
      }
    }
    cout << "NO\n";
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  auto sol = make_unique<S>();
  sol->run();
}


Compilation message (stderr)

bank.cpp: In member function 'void S::run()':
bank.cpp:30:11: warning: variable 'option' set but not used [-Wunused-but-set-variable]
   30 |       int option = 0;
      |           ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...