제출 #354367

#제출 시각아이디문제언어결과실행 시간메모리
354367ogibogi2004은행 (IZhO14_bank)C++14
100 / 100
156 ms1516 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=22; const int MAXM=(1<<MAXN); bool dp[MAXM]; int a[MAXN],n,m; int b[MAXN], pref[MAXN]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>a[i]; pref[i]=pref[i-1]+a[i]; } for(int j=1;j<=m;j++) { cin>>b[j]; } dp[0]=1; for(int mask=0;mask<(1<<m);mask++) { if(!dp[mask])continue; //cout<<mask<<endl; int i=0; int sum=0; for(int j=0;j<m;j++) { if(mask&(1<<j)) { sum+=b[j+1]; } } while(i<n&&pref[i+1]<=sum) { i++; } if(i==n) { cout<<"YES\n"; return 0; } for(int j=0;j<m;j++) { if(!(mask&(1<<j))) { //cout<<sum<<" "<<b[j+1]<<" "<<pref[i+1]<<endl; if(sum+b[j+1]<=pref[i+1]) { dp[mask|(1<<j)]=1; } } } } cout<<"NO\n"; return 0; 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...