Submission #712541

#TimeUsernameProblemLanguageResultExecution timeMemory
712541nishantc1527Bank (IZhO14_bank)C++14
19 / 100
56 ms340 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef debug
#include "debug.h"
#endif
 
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
const int mod = (int) 1e9 + 7;
const int inf = 1061109567;
const ll infll = 4557430888798830399;

const int MAX_N = 1e5 + 5;

int n, m;
int a[MAX_N];
int b[MAX_N];

void solve() {
  cin >> n >> m;
  for(int i = 1; i <= n; i ++) cin >> a[i];
  for(int i = 1; i <= m; i ++) cin >> b[i];
  if(n == 1) {
    int ans = 0;
    for(int i = 0; i < 1 << m; i ++) {
      int curr = 0;
      for(int j = 0; j < m; j ++) if((i >> j) & 1) curr += b[j];
      if(a[1] == curr) {
        ans = 1;
        break;
      }
    }
    if(ans) cout << "YES\n";
    else cout << "NO\n";
  } else cout << "-1\n";
}

int main() {
#ifndef debug
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
#endif

  ios::sync_with_stdio(0);
  cin.tie(0);

  int t = 1;
  // cin >> t;
#ifdef debug
  int i = 1;
  t = 1e5;
#endif
 
  while(t --) {
#ifdef debug
    cout << "Case #" << i ++ << ": ";
#endif
    solve();
    cout << flush;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...