Submission #969210

#TimeUsernameProblemLanguageResultExecution timeMemory
969210dostsBank (IZhO14_bank)C++17
100 / 100
99 ms16980 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 = 2e18,MOD = 1e9+7; void solve() { int n,m; cin >> n >> m; vi a(m+2),b(n+1); for (int i=1;i<=n;i++) cin >> b[i]; for (int j=1;j<=m;j++) cin >> a[j]; a[m+1] = inf; int lim = (1<<m); pii dp[lim]; for (int i=0;i<lim;i++) { dp[i] = {-1,0}; } 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); if (dp[rem].second+a[j+1] > 0) continue; else if (dp[rem].second+a[j+1] == 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]}); } } auto it = max_element(dp,dp+lim); cout << (it->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...