Submission #765578

#TimeUsernameProblemLanguageResultExecution timeMemory
765578LeaRouseBank (IZhO14_bank)C++14
100 / 100
99 ms8532 KiB
#include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); #define ll long long #define ff first #define ss second using namespace std; const int MAX = 25; int A[MAX],B[MAX]; pair<int,int>dp[(1<<21)+5]; void go(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>A[i]; for(int i=1;i<=m;i++) cin>>B[i]; for(int i=0;i<(1<<m);i++){ dp[i]={-1,-1}; } bool ans=false; dp[0]={1,0}; for(int i=0;i<(1<<m);i++){ int mask=i; for(int j=1;j<=m;j++){ if( (mask&( 1<< (j-1) )) ){ int ant=mask ^ (1<<(j-1)); if(dp[ant].ff==-1) continue; int a=dp[ant].ss+B[j]; int b=A[dp[ant].ff]; if(a<b){ if(dp[ant].ff>dp[mask].ff) dp[mask]={dp[ant].ff,a}; } else if(a==b){ if(dp[ant].ff+1>dp[mask].ff) dp[mask]={dp[ant].ff+1,0}; } } } if(dp[mask].ff==n+1) ans=true; } if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl; } int main(){ fastio; go(); 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...