Submission #683692

#TimeUsernameProblemLanguageResultExecution timeMemory
683692oblantisBank (IZhO14_bank)C++17
100 / 100
115 ms8524 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define pb push_back #define ss second #define ff first #define vt vector using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 1e9; const int mod = 1e9 + 7; const int maxn = 2e5 + 12; void solve() { int n, m; cin >> n >> m; int a[n + 1], b[m], rs[1 << m], ind[1 << m]; a[n] = inf; rs[0] = ind[0] = 0; for(int i = 1; i < (1 << m); i++) ind[i] = rs[i] = -1; for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { cin >> b[i]; } bool ok = 0; for(int i = 0; i < (1 << m); i++) { if(ind[i] == n)ok = 1; for(int j = 0; j < m; j++) { if(i & (1 << j)) { continue; } if(ind[i] == -1)continue; int now = a[ind[i]] - rs[i] - b[j]; if(now == 0){ rs[i | (1 << j)] = 0, ind[i | (1 << j)] = ind[i] + 1; } else if(now > 0)rs[i | (1 << j)] = rs[i] + b[j], ind[i | (1 << j)] = ind[i]; } } if(ok)cout << "YES"; else cout << "NO"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tcs = 1; //cin >> tcs; for(int i = 1; i <= tcs; i++) { solve(); } 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...