제출 #1097407

#제출 시각아이디문제언어결과실행 시간메모리
1097407HuyAT은행 (IZhO14_bank)C++14
100 / 100
94 ms8784 KiB
#include<bits/stdc++.h>
#define newl '\n'

const int N = 20;
const int V = 1e7 + 10;
const long long INF = 1e18;
const long long M = 1e9 + 7;

int a[N + 1],b[N + 1],n,m;
std::pair<int,int> f[(1 << N)];

void readData(){
    std::cin >> n >> m;
    for(int i = 0;i < n;++i){
        std::cin >> a[i];
    }
    for(int i = 0;i < m;++i){
        std::cin >> b[i];
    }
}
bool solve(){
    f[0] = {0,-a[0]};
    for(int i = 1;i < (1 << m);++i){
        f[i].second = -1e9;
        for(int j = 0;j < m;++j){
            if((i >> j) & 1){
                int p = i & (~(1 << j));
                if(f[p].second + b[j] <= 0){
                    if(f[p].second + b[j] == 0){
                        f[i] = std::max(f[i],{f[p].first + 1,-a[f[p].first + 1]});
                    }else{
                        f[i] = std::max(f[i],{f[p].first,f[p].second + b[j]});
                    }
                    if(f[i].first == n){
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);std::cout.tie(nullptr);
    readData();
    if(solve()){
        std::cout << "YES\n";
    }else{
        std::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...