제출 #703557

#제출 시각아이디문제언어결과실행 시간메모리
703557gagik_2007은행 (IZhO14_bank)C++17
100 / 100
132 ms16844 KiB
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <chrono> #include <ctime> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <limits> #include <iomanip> #include <unordered_set> #include <unordered_map> #include <fstream> #include <functional> #include <random> #include <cassert> using namespace std; typedef long long ll; typedef long double ld; #define ff first #define ss second ll ttt; const ll INF = 1e18; const ll MOD = 1e9 + 7; const ll N = 21; const ll LG = 18; ll n, m, k; pair<ll, ll> dp[1 << N]; ll a[N]; ll b[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { cin >> b[i]; } if (n > m) { cout << "NO\n"; return 0; } for (int msk = 1; msk < (1 << m); msk++) { for (int i = 0; i < m; i++) { if (msk & (1 << i)) { ll vl = dp[msk ^ (1 << i)].ss + b[i]; ll ind = dp[msk ^ (1 << i)].ff; if (ind == n) { dp[msk] = { ind,vl }; } else if (vl == a[ind]) { dp[msk] = max(dp[msk], make_pair(ind + 1, 0ll)); } else if (vl < a[ind]) { dp[msk] = max(dp[msk], make_pair(ind, vl)); } } } } if (dp[(1 << m) - 1].ff == n) { cout << "YES\n"; } else cout << "NO\n"; return 0; } /// ---- - -------- ------ -------- -- - - - /// Just a reminder. Ubuntu password is I O I /// ---- - -------- ------ -------- -- - - -
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...