Submission #674660

#TimeUsernameProblemLanguageResultExecution timeMemory
674660YENGOYANBank (IZhO14_bank)C++17
100 / 100
119 ms8536 KiB
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee // // 271828___182845__904523__53602__ // // 87___47____13______52____66__24_ // // 97___75____72______47____09___36 // // 999595_____74______96____69___67 // // 62___77____24______07____66__30_ // // 35___35____47______59____45713__ // // eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee // #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <set> #include <map> #include <unordered_map> #include <unordered_map> #include <cmath> #include <climits> #include <algorithm> #include <random> #include <queue> #include <deque> #include <iomanip> #include <string> #include <tuple> #include <bitset> #include <chrono> #include <ctime> #include <fstream> #include <stack> #include <cstdio> using namespace std; using ll = long long; const int N = 1e5 + 5; const ll mod = 1e9 + 7, inf = 1e18; 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]; vector<int> dp(1 << m, -1), mon(1 << m); dp[0] = 0; for (int mask = 0; mask < (1 << m); ++mask) { for (int i = 0; i < m; ++i) { if ((mask & (1 << i)) == 0) continue; int prev = (mask ^ (1 << i)); if (dp[prev] == -1) continue; int need = a[dp[prev]]; if (mon[prev] + b[i] == need) { dp[mask] = dp[prev] + 1; mon[mask] = 0; } else if(mon[prev] + b[i] < need) { dp[mask] = dp[prev]; mon[mask] = mon[prev] + b[i]; } } if (dp[mask] == n) { cout << "YES"; return; } } cout << "NO"; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); //int _; cin >> _; while (_--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...