Submission #1037377

#TimeUsernameProblemLanguageResultExecution timeMemory
1037377vjudge1Bank (IZhO14_bank)C++17
100 / 100
82 ms8648 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << endl #define all(x) x.begin(),x.end() pii dp[(1<<20) + 10]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m;cin>>n>>m; int a[n],b[m]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; sort(a,a+n); for(int mask=0;mask<(1<<m);mask++) { for(int i=0;i<m;i++) { if((mask&(1<<i))!=0) { dp[mask]=max(dp[mask],{dp[(mask^(1<<i))].fi,dp[(mask^(1<<i))].se+b[i]}); if(dp[mask].fi<n && dp[mask].se==a[dp[mask].fi]) dp[mask]={dp[mask].fi+1,0}; } } } // for(int mask=0;mask<(1<<m);mask++) cout<<mask<<": "<<dp[mask].fi<<' '<<dp[mask].se<<'\n';cout<<'\n'; if(dp[(1<<m)-1].fi!=n) cout<<"NO\n"; else cout<<"YES\n"; 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...