제출 #864108

#제출 시각아이디문제언어결과실행 시간메모리
86410820163070은행 (IZhO14_bank)C++14
100 / 100
96 ms8644 KiB
#include <bits/stdc++.h> using namespace std; const int N=110; int n,m; int a[N],b[N]; int main() { cin>>n>>m; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; vector<int> left(1<<m,-1); vector<int> cover(1<<m,-1); left[0]=0; cover[0]=0; for(int s=0;s<(1<<m);s++) { for(int last=0;last<m;last++) { if((s&(1<<last))==0) continue; int prev=s&~(1<<last); if(cover[prev]==-1) continue; int newamt=left[prev]+b[last]; int curt=a[cover[prev]]; if(newamt<curt) { cover[s]=cover[prev]; left[s]=newamt; } else if(newamt==curt) { cover[s]=cover[prev]+1; left[s]=0; } } if(cover[s]==n) { cout<<"YES"; return 0; } } cout<<"NO"; 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...