# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1164401 | jahongir | Bank (IZhO14_bank) | C++20 | 94 ms | 8552 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define pi pair<int,int>
#define all(a) a.begin(),a.end()
#define rand_seed_set srand(chrono::steady_clock::now().time_since_epoch().count())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void setIO(string name = ""){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if(name.empty()){
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}else{
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
struct BIT{
int sz;
vector<ll> tree;
void init(int size){
sz = size;
tree.assign(sz+1,0ll);
}
void update(int x, int val){
if(x==0) return;
for(; x <= sz; x += x&-x)
tree[x] += val;
}
ll get(int x){
ll res = 0;
for(; x; x -= x&-x)
res += tree[x];
return res;
}
};
struct DSU{
int sz;
vector<int> par;
void init(int size){
sz = size;
par.assign(sz,-1);
}
int get(int a){
if(par[a] < 0) return a;
return par[a] = get(par[a]);
}
bool merge(int u, int v){
u = get(u);
v = get(v);
if(u==v) return false;
if(par[u] > par[v]) swap(u,v);
par[u] += par[v];
par[v] = u;
return true;
}
};
const int mod = 1e9+7;
ll exp(ll a, ll b){
ll res = 1;
while(b){
if(b&1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve(){
int n,m;
cin >> n >> m;
vector<int> salary(n),banknote(m);
for(auto &x : salary) cin >> x;
for(auto &x : banknote) cin >> x;
vector<int> dp1(1<<m,-1),dp2(1<<m,-1);
dp1[0] = dp2[0] = 0;
for(int i = 0; i < (1<<m); i++){
for(int j = 0; j < m; j++){
if((i&(1<<j))==0) continue;
int prev = i^(1<<j);
if(dp1[prev]==-1) continue;
int temp = dp2[prev] + banknote[j];
int curr = salary[dp1[prev]];
if(temp < curr){
dp1[i] = dp1[prev];
dp2[i] = temp;
}else if(temp==curr){
dp1[i] = dp1[prev]+1;
dp2[i] = 0;
}
}
if(dp1[i]==n){
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main(){
// setIO("movie");
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
// cin >> t;
while(t--) solve();
}
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... |