Submission #1347732

#TimeUsernameProblemLanguageResultExecution timeMemory
1347732genocidedheusBank (IZhO14_bank)C++20
25 / 100
1095 ms1364 KiB
/*                                                                                                           
                                            .:-=++**###%%%%%%%%%####**+=-:.                                   
                                     .-=*#%@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@%#+=:.                            
                                :=*#@%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@%+:                         
                          .:--+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%+:                      
                     .:-=+===+%%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%#=                    
               ::-==+===+====*%%%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%@@%%%%%%%%%%%%%%%%%%%%=                  
  .:::::---==+=======+++=======*%%%%%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%@%%%%%%%%%%@%%%%%%%%%%%:                
   .::--===+=======++============+*#%%%%%%%%@%%%%%%%%%%%%%%%%%%%%%%%%%@%%%%%%%%%%%@%%%%%%%%%%#=               
             .:::+*==================+**%%%%@%%%@%%%%%%%%%%%%%%%%%%%%%@%%%%%%%%%%%@@%%%#**+====+.             
               .===================++++*#**#%%%%@%%%%%%%%%%%%%%%%%%%%%@%######***++#============+.            
              +%%%%%%%%%%%%%%%%%%%%%%%%@%%%%%%%%@%%%%%%%%%%%%%%%@%%%%%@%%%%###**++=++============+.           
            :#%%%%%%%%%%%%%%%%%%%%%%%%@%%%%@=#%%@%%%%%@%%%%%%%%%@%%%%%@%%%%%%%%%%%%%@##**++=======+           
           *%%%%%%%%%%%%%%@@%%%%%%%%%%@%%%%*--@%@%%%%@@%%%%%%%%%@@%%%%@-+%%%%%%%%%%%@@%%%%%%%#*++==+          
         :%%%%%%%%%%%%%%%@@%%%%%%%%%%%@%%%%-. #%@@%%%@@%%%%%%%%%@*%%%%@: :%%%%%%%%%%%@%%%%%%%%%%%%##.         
        -%%%%%@%%%%%%%%%@@@%%%%%%%%%%@@%%@+.  =%%@%%%@@@%%%%%%%%%-%%%%%:  .#%%%%%%%%%@%%%%%%%%%@%%%%+         
       =%%%%%%@%%%%%%%%@@@@%%%%@%%%%%@%%%#:   .%%@%%%@@@%%%%%%%%#.@%%%%.    +%%%%%%%%@%%%%%%%%%%@%%%%         
      *%%%%%%@%%%%%%%%%@@@%%%%%%@@@%%@%%@-     -@@%%%@@@%%%%%%%%# %%%%*      -%%@@@%%@@%%%%%%%%%%@%%@.        
     =%%%%%%@@%%%%%%%%@@@@%%%%%%%%%@@@%%#       *@@%%@@@@%%%%%%%+ +%%%+    .::=%%%%%%@@%%%%%%%%%%@@%@-        
    :%%%%%%%@%%%%%%%%%@@@@%%%%%%%%%%##%@=:.     .%@%%@@@@%%%%%%%= -@%@+::::.   :%%%%%%@%%%%%%@%%%%@%%=        
    %%%%%%%@@%%%%%%%%@@@@@%%%%%%%%%%:#%*  .::::::+@@%@@@@%%%%%@@=::@@@.         .#%%%%@%%%%%%@@%%%%@%+        
   +%%%%%#-#%%%@%%%%%@@@@@%%%%%%%%%+ *%.          -@%@@@@@%%%%%%   #%%           .#%%%@%%%%%%@@@%%%@@+        
   %%%%%= :%%%%@%%%%@@@@@@%%%%%%%%%  ++            :%@@@@@%%%%%#   +%#            .%%%@%%%%%%@@@@%%%@+        
  =%%%+   #%%%%@%%%%@@@@@@%%%%%%%@-  +:             +@@@@@%%%%%+   :@+             :%%@%%%%%%@@@@@%%%*        
  #%%:   -%%%%%@%%%@@@@@@@@%%%%%%#   =               %@@@@@%%%@-    @=              :%@%%%%%%@@@@@@%%%        
 .@#.    %%%%%%@%%%@@@@@@@@%%%%%@:   .               :@@@@@%%%@.    %.               =@%%%%%%@@@@@@@%%=       
 =#     =%%%%%%@%%%@@@@@@@@%%%%%#  .+-.               =@@@@%%%*     #           .-+#+ @%%%%%@@@@@@@@@%%.      
 +     .%%%%%%%@%%%@@@@@@@@@%%%%+  *@@@%*=:            *@@@%%@-     -       :=#@@@@@# #%%%%%@@@@@@@@@%%*      
       #%%%%%%%*%%%@@@@@@@@@%%%@:  :=+#@@@@@#*=.        #@@%%@         .-+#@@@@@#+-.  %%%%%%@@@@@@@@@@%@:     
      =%%%%%%+  %%%@@@@@@@@@@%%@=       .-+#@@@@@*=:     #@@%*      -*%@@@@%*=:       %%%%%@@@@@@#@@@@%%*     
      %%%%%+.   *%%@@@@@@@@@@@%@@-           -%@@@@@@+   .%@@:    =@@@@@@%+-.         @%%%%@@@@@% -@@@@%@.    
     +%%%*.     -%%@@@@@@@%@@@%@@@.      .-*%@@@@%+-.     .%%       -+#@@@@@@@#+-:   :@%%%%@@@@@+  %%@@%%*    
    -%%*.        %%@@@@@@+=@@@@@@@+   -+%@@@@%*-.          -=           :=*%@@@@@@@= -%%%%@@@@@@.  @%%@@%@.   
   -%*.          +%@@@@@@-.@@@@@@@@ .=@@@@#=.                               .:=*%@#  +%%%%@@@@@*  +@@%%%@%+   
  :+.            .%@@@@@@%=%@@@@@@@-  -*-..                                  ........#%%%%@@@@@.:*@@@@%%@*%   
                  +@@@@@%@@@%@@@@@@*... .....                               ...:-.:..@%%%@@@@@@@# -%@@@%%%::  
                  .@@@@%@@@@@%@@@@@%..........             ....            .........=%%%%@@@@@@@@:  .+@@@%*   
                  *@@@%+*@@@@@%@@@@@=.........        .--=+=======:.       ........:#%%%@@@@@@@@@%     :+%@-  
                 +%@@%  +@@@@@%@@@@@@*-.......      .==============+=       ...:-+%@@%%@@@@@-.*@@@*       .=: 
                -@*..+  #@@@@+%%@@@@@@@@#*=:.       +-================     :=*%@@@@@%%%@@@@@   .+@@=          
               .+       #@@%. .%%@@@@@@@@@@*.-*+=:. =-==============+::=*#@@@@@%=#@@%%@@@@@@:     =@-         
               .        %@*    :%%%@@@@@@@@@: #@@@@@%%##*++++++++++%@@@@@@@@@@@:  *%%@@@@@@@-       ::        
                        %-      -%%%@@@@%-%@@..@@@@@@@@@@+--------=@@@@@@@@@@@+  :%%%@@*-::+=                 
                        .  .::.::-%%%@@@%  *@@#@@@@@@@@#+=---------+%@@@@@@%%%=:.#===+-      :.               
                         ::.     .+*%%%@@-:#%%@@@@@@@@*-------------#@@@@@%%%%+ *+-           .-              
                       ::      :::===+%%%- +#%%%%@@@@@#-============%@@@@%%%%%::.               -             
                     .-             -:*%%* .%%%%%%%@@@%:.          .@@@%%%%#=-:                 .:            
                :-=--+.              .-*%@. *#%%%%%%%@%            -%%%%%%*             .-=++*##%%*.          
               +%%%%%%%%#*+-:          :=@# .%%%%%%%%%%:           +#%%%%%-        :=+*%%%%%%%%%%%%#          
              =+*#%%%%%%%%%%%%*=:        .++ -%%%%%%%%%=           #%%%%%%=   .-+*%%%%%%%%%%#*++=---=         
             =:     :-=*#%%%%%%%%#+-      =%: +%%%%%%%%*          .%%%%%%%#-+#%%%%%%%#*=-:.       ..=.        
            :%%%%*+=:    .-+#%%%%%%%%*-  ::#%: *%%%%%%%%          +#%%%%%%%%%%%%%*=-.    :-=+*#%%%%%%*        
           .==+*#%%%%%#*=-.   -+#%%%%%%#+# .##: *%%%%%%%:         #%%%%%%%%%#+-.   :-=*#%%%%%%%%%%%###:       
           *-:    :-+#%%%%%#+=:  :=*%%%%%%# .##: +%%%%%%*        :%%%%%%%*=.  .-+#%%%%%%%%#*+=-:.     +       
          =#%%%#*=-.   :=*#%%%%%*=: .-*%%%%* .#%- =%%%%%%        *#%%%%%: .-*%%@@@%%#*=-.   .-=++*#%%%%*      
*/
 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool ans =  false;

bool dp[1048577];

void dfs(vector<ll>& salaries,vector<ll>& money,ll mask,ll index){
    bool moved=false;
    ll i;
    if(index==salaries.size()){
        ans=true;
    }
    for(i=0;i<money.size();i++){
        if((mask&(1<<i))==0 && dp[(mask&(1<<i))]==false){
            if(salaries[index]-money[i]>=0){
                mask^=(1<<i);
                dp[mask]=true;
                salaries[index]-=money[i];
                if(salaries[index]==0){
                    index++;
                    moved=true;
                }
                dfs(salaries,money,mask,index);
                if(moved){
                    moved=false;
                    index--;
                }
                salaries[index]+=money[i];
                mask^=(1<<i);
            }
        }
    }
    return;
}

void solve(){
    ll n,m,i,j;
    cin >> n >> m;
    vector<ll>salaries(n);
    vector<ll>money(m);
    for(i=0;i<n;i++){
        cin >> salaries[i];
    }
    for(i=0;i<m;i++){
        cin >> money[i];
    }
    dfs(salaries,money,0,0);
    if(ans){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...