제출 #1232082

#제출 시각아이디문제언어결과실행 시간메모리
1232082warrenn은행 (IZhO14_bank)C++20
100 / 100
109 ms16824 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(){
    int n,m;
    cin>>n>>m;
    int a[n+1];
    for(int q=1;q<=n;q++){
        cin>>a[q];
    }
    int b[m+1];
    for(int q=0;q<m;q++){
        cin>>b[q];
    }

    int dp[(1<<m)][2];
    memset(dp,-1,sizeof dp);
    dp[0][0]=1;
    dp[0][1]=0;

    bool oke=false;
   
    for(int q=1;q<(1<<m);q++){
        for(int w=0;w<m;w++){
            if((q>>w)&1){
                int prev=(q ^ (1<<w));
                if(dp[prev][0]==-1)continue;
                int bayar=a[dp[prev][0]];
                int uang=dp[prev][1]+b[w];

                if(bayar==uang){
                    dp[q][0]=dp[prev][0]+1;
                    dp[q][1]=0;
                }
                else if(bayar>uang){
                    dp[q][0]=dp[prev][0];
                    dp[q][1]=uang;
                }
            }
        }
        if(dp[q][0]==n+1){
            oke=true;
        }
       // cout<<dp[q][0]<<" "<<q<<endl;
    }
    if(oke){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...