Submission #431870

#TimeUsernameProblemLanguageResultExecution timeMemory
431870Aldas25Bank (IZhO14_bank)C++14
100 / 100
183 ms1368 KiB
#include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAXN = 500100, MAXK = 60; //const ll MOD = 998244353; const ll MOD = 1e9+7; const ll INF = 1e17; int n, m; int a[MAXN], b[MAXN]; ll pref[MAXN]; bool dp[1<<22]; int main() { FAST_IO; cin >> n >> m; FOR(i, 1, n) cin >> a[i]; FOR(i, 0, m-1) cin >> b[i]; FOR(i, 1, n) pref[i] = pref[i-1] + a[i]; ll sumA = 0, sumB = 0; FOR(i, 1, n) sumA += a[i]; FOR(i, 0, m-1) sumB += b[i]; if (sumB < sumA) { cout << "NO\n"; return 0; } dp[0] = true; FOR(mask, 1, (1<<m)-1) { int sum = 0; FOR(i, 0, m-1) if (mask & (1<<i)) sum += b[i]; if (sum > pref[n]) continue; int le = 0, ri = n; while (le < ri) { int mid = (le+ri)/2; if (pref[mid] >= sum) ri = mid; else le = mid+1; } int id = le; FOR(i, 0, m-1) { if (! (mask & (1<<i))) continue; int prevSum = sum - b[i]; if (prevSum < pref[id-1]) continue; if (dp[mask ^ (1<<i)]) dp[mask] = true; } if (sum == pref[n] && dp[mask]) { cout << "YES\n"; return 0; } } 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...