Submission #586780

#TimeUsernameProblemLanguageResultExecution timeMemory
586780BhavayGoyalBank (IZhO14_bank)C++14
100 / 100
185 ms8532 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define ll long long #define ld long double #define ar array #define vi vector<int> #define vii vector<vector<int>> #define pii pair<int, int> #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second const int MOD = 1e9+7; const int inf = 1e9; const ll linf = 1e18; const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; // -------------------------------------------------- Main Code -------------------------------------------------- int a[20], b[20]; int n, m; pii dp[(1<<20)]; pii sol(int mask) { if (mask == 0) return {0, 0}; if (dp[mask].f != -1 && dp[mask].s != -1) return dp[mask]; pii ans = {0, 0}; for (int i = 0; i < m; i++) { if (mask&(1<<i)) { pii x = sol(mask^(1<<i)); int prevPer = x.f; int left = x.s; if (left+b[i] == a[prevPer]) prevPer++, left = 0; else if (left+b[i] < a[prevPer]) left += b[i]; ans = max(ans, {prevPer, left}); } } return dp[mask] = ans; } void sol() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int i = 0; i < (1<<m); i++) dp[i].f = -1, dp[i].s = -1; for (int i = 0; i < (1<<m); i++) { if (sol(i).f == n) { cout << "YES" << endl; return; } } cout << "NO" << endl; } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { sol(); } return 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...