Submission #1131244

#TimeUsernameProblemLanguageResultExecution timeMemory
1131244catsarecool5530Bank (IZhO14_bank)C++20
0 / 100
2 ms324 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; // #define endl "\n"; #define all(x) x.begin(), x.end() ll MOD = 1e9+7; struct Obj { int used, soFar; }; void solve() { int n, m; cin >> n >> m; if (n > m) { cout << "NO\n"; return; } vector<int> people(n); for (int& i : people) { cin >> i; } vector<int> money(m); for (int& i : money) { cin >> i; } vector<Obj> dp((1 << m), {-1, -1}); dp[0] = {0, 0}; for (int mask = 0; mask < (1 << m); mask++) { if (dp[mask].used == -1) continue; if (dp[mask].used == n) { cout << "YES\n"; return; } for (int i = 0; i < m; i++) { //cerr << mask << ' ' << i << endl; if (mask & (1 << i)) continue; ll newMask = mask | (1 << i); if (money[i] + dp[mask].soFar > people[dp[mask].used]) { continue; } if (money[i] + dp[mask].soFar == people[dp[mask].used]) { dp[newMask] = {dp[mask].used + 1, 0}; } else { dp[newMask] = {dp[mask].used, money[i] + dp[mask].soFar}; } } } cout << "NO\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); freopen("bank.in", "r", stdin); freopen("bank.out", "w", stdout); ll t = 1; //cin >> t; while (t--) { solve(); } }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("bank.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("bank.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...