Submission #406555

#TimeUsernameProblemLanguageResultExecution timeMemory
406555CrouchingDragonBank (IZhO14_bank)C++17
100 / 100
105 ms8644 KiB
#include "bits/stdc++.h" using namespace std; #define endl '\n' #define debug(x) cerr << #x << " == " << (x) << '\n'; #define all(x) begin(x), end(x) using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; vector<int> a(N), b(M); for (auto& x : a) cin >> x; for (auto& x : b) cin >> x; partial_sum(all(a), begin(a)); string ans = "NO"; vector<int> dp(1 << M), sum(1 << M); for (int j = 0; j < M; ++j) sum[1 << j] = b[j]; for (int mask = 0; mask < (1 << M); ++mask) { int lsb = mask & -mask; sum[mask] = sum[mask ^ lsb] + sum[lsb]; if (dp[mask] == N) { ans = "YES"; break; } for (int j = 0; j < M; ++j) { int nmask = mask | 1 << j, nsum = sum[mask] + b[j]; if ((mask >> j & 1) == 0 && nsum <= a[dp[mask]]) { dp[nmask] = dp[mask] + (nsum == a[dp[mask]] ? 1 : 0); } } } cout << ans << endl; exit(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...