제출 #1165982

#제출 시각아이디문제언어결과실행 시간메모리
1165982lidplf은행 (IZhO14_bank)C++20
100 / 100
99 ms16772 KiB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define MOD2 998244353
using namespace std;
void solve(int cas){ 
    int n,m; cin>>n>>m;
    vector<ll> people(n), bank(m);
    for (auto& a: people) cin>>a;
    for (auto& a: bank) cin>>a;
    vector<pair<ll,ll>> dp(1 << m);
    for (int i = 1; i < (1<<m); i++){
        for (int j = 0; j < m; j++){
            if (i&(1<<j)){
                if (dp[i^(1<<j)].second + bank[j]==people[dp[i^(1<<j)].first]){
                    dp[i] = max(dp[i], pair<ll,ll>(dp[i^(1<<j)].first + 1,0));
                }
                else{
                    dp[i] = max(dp[i], pair<ll,ll>(dp[i^(1<<j)].first, dp[i^(1<<j)].second + bank[j]));
                }
            }
        }
        if (dp[i].first==n){
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin>>t;
    for (int i = 1; i <= t; i++){
        solve(i);
    }
    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...