# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1272322 | zagaro | Bank (IZhO14_bank) | C++20 | 277 ms | 303780 KiB |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
/**zagaro & lauren <3**/
#define mod 1000000007 //1e9 + 7
#define pi acos(-1)
#define wl while
#define str string
#define ENDL "\n"
#define sal ' '
#define tp_set ll
#define prc(n) cout.precision(n);cout<<fixed;
#define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef bool bl;
typedef char car;
using namespace std;
using namespace __gnu_pbds;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen("bank.in", "r", stdin);
freopen("bank.out", "w", stdout);
int n, m;
bl B=false;
cin>>n>>m;
vector<int> vec(n+2, 0);
vector<int> bil(m);
vector<vector<short int > > dp(n+2, vector<short int > ((1<<m), -1));
dp[0][0] = 0;
for(int i=1;i<=n;i++)cin>>vec[i];
for(int i=0;i<m;i++)cin>>bil[i];
for(int i=0;i<=n;i++){
for(int j=0;j<(1<<m);j++){
if(dp[i][j] == 0){
dp[i+1][j] = vec[i+1];
}
else if(dp[i][j] > 0){
for(int k=0;k<m;k++){
if((j&(1<<k)) == 0 && dp[i][j] >= bil[k]){
dp[i][j^(1<<k)] = dp[i][j]-bil[k];
}
}
}
}
}
for(int i=0;i<(1<<m);i++){
if(dp[n][i] == 0){
B=true;
break;
}
}
if(B)cout<<"YES\n";
else cout<<"NO\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |