Submission #722575

#TimeUsernameProblemLanguageResultExecution timeMemory
722575PVSekharBank (IZhO14_bank)C++14
100 / 100
89 ms8612 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1000000007; int main() { int n,m; cin>>n>>m; int a[n],b[m]; for (int i = 0; i < n; i++)cin>>a[i]; for (int i = 0; i < m; i++)cin>>b[i]; vector<pair<int,int>> dp((1<<m),{0,-1});// keeping 'a' fixed stores the index till which the first part of the permutaion can be used and what more is needed to pay a[index+1] dp[0].second=a[0]; bool check=false; pair<int,int> p; for (int i = 1; i < (1<<m); i++) { for (int j = 0; j < m; j++) { if(i&(1<<j)){ p=dp[i^(1<<j)]; // cout<<i<<j<<endl; if(p.second<b[j])continue; p.second-=b[j]; // cout<<i<<" "<<j<<p.first<<" "<<p.second<<endl; if(p.second==0){ p.first++; if(p.first==n){ check=true; dp[i]=p; break; } p.second=a[p.first]; } if(p.first>=dp[i].first){ dp[i]=p; } } } } if(check){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } 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...