제출 #1128227

#제출 시각아이디문제언어결과실행 시간메모리
1128227ImperialALEN은행 (IZhO14_bank)C++17
0 / 100
1 ms836 KiB
#include <bits/stdc++.h> #define F first #define S second #define ll long long #define int long long #define pb push_back #define all(x) (x.begin(),x.end()) #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; const ll N = 2e4+9, INF = 1e18 , inf = 1e9 , mod = 1e9+7; int a[22]; int b[22]; vector<int>dp[N]; map<int,int>mp; signed main(){ ios; int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } vector<int>v; for(int i=1;i<=m;i++){ cin>>b[i]; v.pb(b[i]); } sort(a+1,a+1+n); sort all(v); for(int ind=1;ind<=n;ind++){ set<int>st; int x=0; for(auto to:v)x+=to; if(a[ind]>x){ cout<<"NO"; return 0; } for(int i=0;i<v.size();i++){ for(int pos=a[ind];pos>=1;pos--){ if(pos-v[i]>0 && dp[pos-v[i]].size()>0){ vector<int>emp; swap(emp,dp[pos]); for(auto to:dp[pos-v[i]])dp[pos].pb(to); dp[pos].pb(v[i]); }else if(pos-v[i]==0){ vector<int>emp; swap(emp,dp[pos]); dp[pos].pb(v[i]); } } } vector<int>nw; for(auto to:dp[a[ind]]){ mp[to]++; cout<<to<<" "; } cout<<'\n'; for(auto to:v){ if(mp[to]>0){ mp[to]--; }else nw.pb(to); } swap(nw,v); if(dp[a[ind]].empty()){ cout<<"NO\n"; return 0; } for(int i=1;i<=x;i++){ vector<int>emp; swap(emp,dp[i]); } } cout<<"YES\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...