제출 #969216

#제출 시각아이디문제언어결과실행 시간메모리
969216dosts은행 (IZhO14_bank)C++17
100 / 100
94 ms8792 KiB
//Dost SEFEROĞLU #pragma GCC optimize("O3,unroll-loops,Ofast") #include <bits/stdc++.h> using namespace std; //#define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define vi vector<int> const int N = 5e2+1,inf = 2e9,MOD = 1e9+7; void solve() { int n,m; cin >> n >> m; vi a(m+2),b(n+2); a[m+1] = b[n+1] = inf; for (int i=1;i<=n;i++) cin >> b[i]; for (int j=1;j<=m;j++) cin >> a[j]; sort(a.begin()+1,a.end()); int lim = (1<<m); pii dp[lim]; for (int i=0;i<lim;i++) dp[i] = {-1,0}; pii mx = {0,-b[1]}; dp[0] = {0,-b[1]}; for (int i=1;i<lim;i++) { for (int j=0;j<m;j++) { if (!(i&(1<<j))) continue; int rem = i^(1<<j); int v = dp[rem].second+a[j+1]; if (v > 0) continue; else if (v == 0){ dp[i] = max(dp[i],{dp[rem].ff+1,-b[dp[rem].ff+2]}); } else dp[i] = max(dp[i],{dp[rem].first,dp[rem].second+a[j+1]}); } mx = max(mx,dp[i]); }; cout << (mx.ff == n ? "YES\n" : "NO\n"); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) 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...