#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream cin("bank.in");
ofstream cout("bank.out");
int n,m;
cin>>n>>m;
vector<int> a(n),b(m);
for(auto&v:a) cin>>v;
for(auto&v:b) cin>>v;
bool cc=false;
vector<pair<long long,long long>> dp(1<<m,{0,0});
dp[0]={0,0};
for(int i=1;i<(1<<m);i++){
for(int j=0;j<m;j++){
if(i&(1<<j)){
pair<long long,long long> mx;
mx=dp[i^(1<<j)];
if(mx.first==-1) continue;
if(a[mx.first] == mx.second + b[j]){
mx.second=0;
mx.first++;
dp[i]=mx;
}
else if((a[mx.first] > mx.second + b[j])&&(dp[i].first <= mx.first)){
mx.second+=b[j];
dp[i]=mx;
}
}
}
if(dp[i].first == n){
cc=true;break;
}
}
if(cc) cout<<"Yes";
else cout<<"No";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |