Submission #475599

#TimeUsernameProblemLanguageResultExecution timeMemory
475599nohaxjustsofloBank (IZhO14_bank)C++17
100 / 100
125 ms8508 KiB
#include <bits/stdc++.h> #include <iostream> using namespace std; typedef long long ll; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set; const int mxN = 20; const int mod = 998244353; const int mxlogN = 20; const int mxK = 26; int a[mxN]; int b[mxN]; int leftover[1<<mxN]; int people[1<<mxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("bank.in", "r",stdin); //freopen("bank.out", "w",stdout); int n, m; cin >> n >> m; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; for(int i = 0; i < (1<<m); i++) { people[i] = -1; } people[0] = 0; leftover[0] = 0; for(int i = 0; i < (1<<m); i++) { for(int j = 0; j < m; j++) { if(i&(1<<j)) { int mask = i^(1<<j); if(people[mask]==-1)continue; int covered = people[mask]; int lef = leftover[mask]; if(b[j]+lef < a[covered]) { people[i] = people[mask]; leftover[i] = lef+b[j]; } else if(b[j]+lef == a[covered]) { people[i] = people[mask]+1; leftover[i] = 0; } } } if(people[i]==n) { cout << "YES\n"; return 0; } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...