제출 #250394

#제출 시각아이디문제언어결과실행 시간메모리
250394srvlt은행 (IZhO14_bank)C++14
100 / 100
202 ms4608 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define ld long double #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) (int)(x).size() template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m, a[20], b[20], dp[1 << 20]; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif memset(& dp, -1, sizeof(dp)); cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; dp[0] = 0; int cur = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << m); j++) { if (dp[j] >= cur) { for (int k = 0; k < m; k++) { if (j >> k & 1) continue; if (dp[j] + b[k] <= cur + a[i]) dp[j ^ (1 << k)] = dp[j] + b[k]; } } } cur += a[i]; } for (int i = 0; i < (1 << m); i++) if (dp[i] == cur) return cout << "YES", 0; cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...