제출 #1089285

#제출 시각아이디문제언어결과실행 시간메모리
1089285vjudge1은행 (IZhO14_bank)C++17
19 / 100
5 ms348 KiB
#include <bits/stdc++.h> //qwerty47924692 using namespace std; using ll = int; #define f first #define s second const ll N=3e5+29; ll n,m,a[N],b[N],ans,p[N],used[N],total[N],have,need; void f(ll x,ll sum,ll i){ if(x==m){ if(sum==a[i]&&i<n){ need-=a[i]; for(ll i=1;i<=m;i++){ if(used[i]){ total[i]=1; have-=b[i]; } } f(0,0,i+1); for(ll i=1;i<=m;i++){ if(used[i]){ total[i]=1; have+=b[i]; } } need+=a[i]; } if(i==n&&sum==a[n]){ ans=1; // for(ll i=1;i<=m;i++)cout<<used[i]<<' '; return; } return; } x++; if(!total[i])used[x]=1; if(!total[i]&&sum+b[x]<=a[i]&&need<=have)f(x,sum+b[x],i); used[x]=0; f(x,sum,i); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; if(n>m){ cout<<"NO"; return 0; } for(ll i=1;i<=n;i++){ cin>>a[i]; need-=a[i]; } for(ll i=1;i<=m;i++){ cin>>b[i]; have+=b[i]; p[i]=i; } f(0,0,1); cout<<(ans ? "YES" : "NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...