Submission #1001492

#TimeUsernameProblemLanguageResultExecution timeMemory
1001492IcelastBank (IZhO14_bank)C++17
100 / 100
76 ms16876 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ int n, m; cin >> n >> m; vector<ll> a(n+2), b(m+1); for(int i = 1; i <= n; i++){ cin >> a[i]; } a[n+1] = INF; for(int i = 1; i <= m; i++){ cin >> b[i]; } int full = (1<<m)-1; vector<ll> dp(full+1, -INF), left(full+1, -INF); dp[0] = 0; left[0] = 0; for(int mask = 0; mask <= full; mask++){ for(int i = 0; i < m; i++){ if((mask&(1<<i)) == 0) continue; if(left[mask^(1<<i)] + b[i+1] == a[dp[mask^(1<<i)]+1]){ if(dp[mask] < dp[mask^(1<<i)]+1){ dp[mask] = dp[mask^(1<<i)]+1; left[mask] = 0; } }else{ if(dp[mask] < dp[mask^(1<<i)]){ dp[mask] = dp[mask^(1<<i)]; left[mask] = left[mask^(1<<i)]+b[i+1]; } } } } ll mx = -1; for(int mask = 0; mask <= full; mask++){ mx = max(mx, dp[mask]); } if(mx == n){ cout << "YES"; }else{ cout << "NO"; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...