Submission #337642

#TimeUsernameProblemLanguageResultExecution timeMemory
337642BY_KUTBILIMBank (IZhO14_bank)C++14
44 / 100
1080 ms364 KiB
/** @BY_KUTBILIM **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).end() int main(){ ios_base::sync_with_stdio(false); cin.tie(); int n, m; cin >> n >> m; int a[n], b[m]; for(int i = 0; i < n; i++)cin >> a[i]; int sum = 0; for(int j = 0; j < m; j++){ cin >> b[j]; sum += b[j]; } if(n == 1){ for(int mask = 0; mask < (1 << m); mask++){ int num = a[0]; for(int i = 0; i < m; i++){ if((1 << i) & mask){ num -= b[i]; } } if(num == 0){ cout << "YES\n"; return 0; } } cout << "NO\n"; } else{ vector<int> index; for(int i = 0; i < m; i++){ index.pb(i); } bool ok = false; do{ int j = 0; for(int i = 0; i < n; i++){ if(j == m)break; int num = a[i]; while(j < m and b[index[j]] <= num){ num -= b[index[j]]; j++; } if(num != 0)break; if(num == 0 and i == n - 1)ok = true; } if(ok)break; }while(next_permutation(all(index))); if(ok)cout << "YES\n"; else cout << "NO\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...