Submission #824362

#TimeUsernameProblemLanguageResultExecution timeMemory
824362andecaandeciBank (IZhO14_bank)C++17
19 / 100
2 ms3540 KiB
# include <bits/stdc++.h> # define int long long # define vi vector<int> # define pb push_back # define pii pair<int, int> # define fi first # define se second # define endl '\n' # define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, m, a[21], b[21], memo[21][20005]; int dp(int idx, int sum) { if(idx>m) { if(sum==a[1]) return 1; return 0; } if(memo[idx][sum]!=-1) return memo[idx][sum]; int best=dp(idx+1, sum); best=max(best, dp(idx+1, sum+b[idx])); return memo[idx][sum]=best; } void solve() { memset(memo, -1, sizeof(memo)); cin >> n >> m; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=m; i++) cin >> b[i]; if(dp(1, 0)>0) cout << "YES" << endl; else cout << "NO" << endl; } signed main() { jess; 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...