Submission #1338610

#TimeUsernameProblemLanguageResultExecution timeMemory
1338610Born_To_Laugh은행 (IZhO14_bank)C++17
100 / 100
121 ms8648 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(AC) AC.begin(), AC.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e9 + 7;

const int maxn = 25;
int n, m;
pair<int, int> dp[1 << 21];
int a[maxn], b[maxn];

void solve(){
    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 i = 1; i < (1 << m); ++i){
        for(int j=0; j<m; ++j){
            if(i & (1 << j)){
                int sth = i & ~(1 << j);
                dp[i] = max(dp[i], dp[sth]);
                if(dp[sth].fi < n){
                    if(dp[sth].se + b[j] < a[dp[sth].fi]){
                        dp[i] = max(dp[i], {dp[sth].fi, dp[sth].se + b[j]});
                    }
                    else if(dp[sth].se + b[j] == a[dp[sth].fi]){
                        dp[i] = max(dp[i], {dp[sth].fi + 1, 0});
                    }
                }
            }
        }
    }
    if(dp[(1 << m) - 1].fi == n) cout << "YES\n";
    else cout << "NO\n";
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    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...