Submission #887027

#TimeUsernameProblemLanguageResultExecution timeMemory
887027a_l_i_r_e_z_aBank (IZhO14_bank)C++17
100 / 100
85 ms8668 KiB
// In the name of Allah // Khodaya khodet komak kon // Hope is last to die // Let's go // Hello today I decided to solve at least 4 great problems per day // 2023/11/24 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define pb push_back #define S second #define F first #define mp make_pair #define smax(x, y) (x) = max((x), (y)) #define smin(x, y) (x) = min((x), (y)) #define all(x) (x).begin(), (x).end() #define set_dec(x) cout << fixed << setprecision(x); #define sz(x) ((int)(x).size()) #define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); const int maxn = 20 + 5, maxB = (1ll << 20); const int inf = 1e9 + 7; int a[maxn], b[maxn]; pii dp[maxB]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 mask = 0; mask < (1ll << m); mask++) dp[mask].F = -1; dp[0].F = 0; for(int mask = 0; mask < (1ll << m); mask++){ if(dp[mask].F == -1) continue; if(dp[mask].F == n && dp[mask].S == 0){ cout << "YES\n"; return 0; } for(int i = 0; i < m; i++){ if((1ll << i) & mask) continue; if(dp[mask].S + b[i] > a[dp[mask].F]) continue; else if(dp[mask].S + b[i] == a[dp[mask].F]){ dp[mask | (1ll << i)] = mp(dp[mask].F + 1, 0); } else{ dp[mask | (1ll << i)] = mp(dp[mask].F, dp[mask].S + b[i]); } } } cout << "NO\n"; 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...