Submission #766523

#TimeUsernameProblemLanguageResultExecution timeMemory
766523dxz05Bank (IZhO14_bank)C++17
100 / 100
99 ms8540 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<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]; vector<pair<int, int>> dp(1 << m, make_pair(-1, -1)); dp[0] = make_pair(0, 0); int before = 0, person = 0; for (int mask = 0; mask < (1 << m); mask++){ if (dp[mask] == make_pair(-1, -1)) continue; if (dp[mask] == make_pair(n, 0)){ cout << "YES" << endl; return 0; } int j = dp[mask].first, has = dp[mask].second; if (j >= n) continue; for (int i = 0; i < m; i++){ if (mask & (1 << i)) continue; if (has + b[i] < a[j]){ dp[mask | (1 << i)] = max(dp[mask | (1 << i)], make_pair(j, has + b[i])); } else if (has + b[i] == a[j]){ dp[mask | (1 << i)] = max(dp[mask | (1 << i)], make_pair(j + 1, 0)); } } } cout << "NO" << endl; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:18:9: warning: unused variable 'before' [-Wunused-variable]
   18 |     int before = 0, person = 0;
      |         ^~~~~~
bank.cpp:18:21: warning: unused variable 'person' [-Wunused-variable]
   18 |     int before = 0, person = 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...