Submission #855036

#TimeUsernameProblemLanguageResultExecution timeMemory
855036hungt58Bank (IZhO14_bank)C++14
71 / 100
34 ms456 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll int #define TIME (1.0 * clock() / CLOCKS_PER_SEC) ll n,m,a[21],b[21],res,kt[10010],w=0; void dao(ll i) { for (ll j=1;j<=n;j++) if (a[j]>=b[i]) { a[j]-=b[i]; if (a[j]==0) res--; w++; if (w==10000000) {cout<<"NO";exit(0);} if (m-i>=res) { if (i==m) {if (res==0){cout<<"YES";exit(0);}} else dao(i+1); } if (a[j]==0) res++; a[j]+=b[i]; } } int main() { ios_base :: sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>m; for (ll i=1;i<=n;i++) cin>>a[i],kt[a[i]]++; for (ll i=1;i<=m;i++) { cin>>b[i]; if (kt[b[i]]>0) kt[b[i]]--,i--,m--; } vector<ll> c; for (ll i=1;i<=n;i++) { if (kt[a[i]]>0) c.push_back(a[i]); kt[a[i]]--; } n=0; for (ll j:c) a[++n]=j; n++; a[n]=100010; res=n-1; dao(1); cout<<"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...