제출 #337637

#제출 시각아이디문제언어결과실행 시간메모리
337637BY_KUTBILIM은행 (IZhO14_bank)C++14
0 / 100
1062 ms384 KiB
/** @BY_KUTBILIM **/
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).end()


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();

    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    for(int i = 0; i < n; i++)cin >> a[i];
    int sum = 0;
    for(int j = 0; j < m; j++){
        cin >> b[j];
        sum += b[j];
    }
    if(n == 1){
        vector<int> dp(sum+10, 0);
        dp[0] = 1;
        for(int i = 0; i < m; i++){
            for(int j = sum; j >= b[i]; j--){
                if(dp[j-b[i]])dp[j] = 1;
            }
        }
        if(dp[n])cout << "YES\n";
        else cout << "NO\n";
    } else{
        vector<int> index;
        for(int i = 0; i < m; i++){
            index.pb(i);
        }
        bool ok = false;
        do{
            int j = 0;
            for(int i = 0; i < n; i++){
                if(j == m)break;
                int num = a[i];
                while(j < m and b[index[j]] <= num){
                    num -= b[index[j]];
                }
                if(num != 0)break;
                if(num == 0 and i == n - 1)ok = true;
            }
            if(ok)break;
        }while(next_permutation(all(index)));
        if(ok)cout << "YES\n";
        else 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...