Submission #885211

#TimeUsernameProblemLanguageResultExecution timeMemory
885211parlimoosBank (IZhO14_bank)C++14
100 / 100
82 ms8792 KiB
//Be Name KHODA #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define pp pop_back #define cl clear #define bg begin #define lb lower_bound #define ub upper_bound #define arr(x) array<int , x> #define endl '\n' int n , m; vector<int> a , b; int dp[(1 << 20)][2]; void f(){ dp[0][0] = 0 , dp[0][1] = 0; for(int msk = 0 ; msk < (1 << m) ; msk++){ for(int j = 0 ; j < m ; j++){ if((msk >> j) & 1){ int lst = dp[msk ^ (1 << j)][0]; int d = dp[msk ^ (1 << j)][1] + b[j]; if(d < a[lst]){ dp[msk][0] = lst; dp[msk][1] = d; }else if(d == a[lst]){ dp[msk][0] = lst + 1; dp[msk][1] = 0; } } } if(dp[msk][0] == n){ cout << "YES"; exit(0); } } cout << "NO"; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0 ; i < n ; i++){ int d; cin >> d; a.pb(d); } for(int i = 0 ; i < m ; i++){ int d; cin >> d; b.pb(d); } for(int msk = 0 ; msk < (1 << m) ; msk++){ dp[msk][0] = -1; dp[msk][1] = 0; } f(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...