Submission #855042

#TimeUsernameProblemLanguageResultExecution timeMemory
855042hungt58Bank (IZhO14_bank)C++14
19 / 100
1 ms348 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,suma=0,sumb=0; void dao(ll i) { for (ll j=1;j<=n;j++) { if (a[j]>=b[i]&&suma<=sumb) { a[j]-=b[i]; if (j==n-1) suma-=b[i]; sumb-=b[i]; if (a[j]==0) res--; w++; if (w==100000000) {cout<<"YES";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++; if (j==n-1) suma+=b[i]; a[j]+=b[i]; sumb+=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--; } for (ll i=1;i<=m;i++) sumb+=b[i]; vector<ll> c; for (ll i=1;i<=n;i++) { if (kt[a[i]]>0) c.push_back(a[i]),suma+=a[i]; kt[a[i]]--; } n=0; for (ll j:c) a[++n]=j; if (n==0) {cout<<"YES";exit(0);} 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...