Submission #1268199

#TimeUsernameProblemLanguageResultExecution timeMemory
1268199nikaa123Bank (IZhO14_bank)C++20
100 / 100
94 ms8668 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long #define eb emplace_back #define mp make_pair #define pb push_back #define pp pop_back #define endl '\n' #define ff first #define ss second #define stop exit(0) #define sz(x) (int)x.size() #define pause system("pause") #define all(x) (x).begin(), (x).end() #define deb(x) cout << #x << "-" << x << endl typedef char chr; typedef string str; typedef long long ll; typedef vector<int> vii; typedef pair<int, int> pii; const long long INF = LLONG_MAX; const int inf = INT_MAX; const int mod = 998244353; const int MOD = 1e9 + 7; const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; const double PI = 2 * acos(0.0); const int N = 2e6 + 5; int n,m,dp[N],res[N],a[N],b[N]; inline void test_case() { int n,m; 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 k = 0; k <= (1<<m)-1; k++) { dp[k] = -1; res[k] = -1; } dp[0] = 0; res[0] = 0; for (int k = 0; k <= (1 << m)-1; k++) { for (int last = 0; last < m; last++) { if (k & (1<<last)) { int pk = k - (1<<last); if (dp[pk] == -1) continue; int nres = b[last] + res[pk]; int val = a[dp[pk]]; if (nres < val) { dp[k] = dp[pk]; res[k] = nres; } if (nres == val) { dp[k] = dp[pk]+1; res[k] = 0; } } } if (dp[k] == n) { cout << "YES" << endl; return; } } cout << "NO" << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; // cin >> T; while (T--) { test_case(); } 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...