Submission #1127547

#TimeUsernameProblemLanguageResultExecution timeMemory
1127547Haciyev12Bank (IZhO14_bank)C++20
44 / 100
1094 ms328 KiB
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
using namespace std;
const ll INF = 1e18, mod = 1e9 + 7, N = 2e5 + 5;
ll gcd(ll a, ll b){
 if(b == 0){
 return a;
 }
 return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    return (a / gcd(a,b)) * b;
}
vector<ll>vis(25, 0);
ll n,m;
ll a[25];
ll b[25];
void dfs(ll x){
    if(x == n){
        yes;
        exit(0);
    }
    for(int i = 0; i < m; i++){
        if(!vis[i]){
            if(b[i] <= a[x]){
                a[x] -= b[i];
                vis[i] = 1;
                if(a[x] == 0){
                    dfs(x + 1);
                }
                else{
                    dfs(x);
                }
                vis[i] = 0;
                a[x] += b[i];
            }
        }
    }
}
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];
    }
  
    ll c;
    if(n == 1){
    for(int i = 1; i <= (1 << m); i++){
        c = 0;
        for(int j = 0; j < m; j++){
            
            if(i & (1 << j)){
                c += b[j];
            }
        }
            if(c == a[0]){
                yes;
                return;
            }
        
    }
    
    no;
    return;
    }
    sort(a, a + n);
    sort(b, b + m);
    dfs(0);
    no;
}
int main() {
    fast;
    ll t = 1;
   // cin >> t;
    while(t--){
        solve();
    }
    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...