제출 #1301941

#제출 시각아이디문제언어결과실행 시간메모리
1301941EkinOnal은행 (IZhO14_bank)C++20
100 / 100
125 ms16836 KiB
#include <bits/stdc++.h> using namespace std; // #define double long double #define int long long #define pb push_back #define vi vector<int> #define vpii vector<pair<int,int>> #define MAX 200005 #define f first #define s second const int INF = 1e18; #define pii pair<int,int> void solve(){ int n,m; cin>>n>>m; vi a(n+2,INF); for(int i=1;i<=n;i++) cin>>a[i]; vi b(m); for(int i=0;i<m;i++) cin>>b[i]; vpii dp(1<<20,{-INF,-INF}); dp[0]={0,0}; for(int i=0;i<(1<<m);i++){ for(int j=0;j<m;j++){ if(i&(1<<j)) continue; dp[i|(1<<j)]=max(dp[i],dp[i|(1<<j)]); if(dp[i].f==-INF) continue; int newtot=dp[i].s+b[j]; if(newtot>a[dp[i].f+1]) continue; else if(newtot==a[dp[i].f+1]) dp[i|(1<<j)]=max(dp[i|(1<<j)],{dp[i].f+1,0ll}); else if(newtot<a[dp[i].f+1]) dp[i|(1<<j)]=max(dp[i|(1<<j)],{dp[i].f,newtot}); } } if(dp[(1<<m)-1].f>=n) cout<<"YES\n"; else cout<<"NO\n"; // cout<<dp[20].f<<endl; // cout<<dp[(1<<n)-1].f<<endl; } int32_t main(){ // freopen("cowrun.in","r",stdin); // freopen("cowrun.out","w",stdout); int t=1; // cin>>t; while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...