Submission #638024

#TimeUsernameProblemLanguageResultExecution timeMemory
638024kakayoshiBank (IZhO14_bank)C++14
100 / 100
146 ms16808 KiB
#include <bits/stdc++.h> using namespace std; #define forw(i,a,b) for(ll i=a;i<=b;i++) #define forb(i,a,b) for(ll i=a;i>=b;i--) #define fi first #define se second #define pb push_back #define pu push #define all(a) a.begin(),a.end() #define getbit(mask,i) ((mask>>(i))&1) #define getnum(i) (1<<(i)) #define add(a,b) (a)=((a)+(b))%mod #define minimize(a,b) (a)=min((a),(b)) typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll maxN=2e6+5; const ll mod=1e9+7; const ll oo=1e18; const int tx[2]={0,1}; const int ty[2]={1,0}; ll n,m,a[22],b[22]; pll dp[maxN]; pll cmp(pll a, pll b) { if (a.fi>b.fi) return a; return b; } void solve() { cin>>n>>m; forw(i,1,n) cin>>a[i]; forw(i,1,m) cin>>b[i]; forw(mask,1,(1<<m)-1) forw(i,1,m) { if ((mask&(1<<(i-1)))==0) continue; ll prev=mask^(1<<(i-1)); ll pos=dp[prev].fi; ll val=dp[prev].se+b[i]; if (val<a[pos+1]) dp[mask]=cmp(dp[mask],{pos,val}); if (val==a[pos+1]) dp[mask]=cmp(dp[mask],{pos+1,0}); } forw(mask,1,(1<<m)-1) if (dp[mask].fi==n) { cout<<"YES"; return; } cout<<"NO"; return; } int main() { ios::sync_with_stdio(0); cin.tie(0); //freopen("bruh.inp","r",stdin); //freopen("bruh.out","w",stdout); int t=1; //cin>>t; while(t--) 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...