Submission #551867

#TimeUsernameProblemLanguageResultExecution timeMemory
551867antontsiorvasBank (IZhO14_bank)C++14
100 / 100
108 ms8508 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; const int MAXN = 20, MAXM = 20; int n, m, sal[MAXN+5], bank[MAXM+5]; pair<int,int> dp[1<<MAXN+5]; int main(){ scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%d",&sal[i]); for(int i=1; i<=m; i++) scanf("%d",&bank[i]); int cs = (1<<m)-1; dp[0] = {0,0}; for(int i=1; i<=cs; i++){ dp[i] = {-1,-1}; for(int j=1; j<=m; j++){ if(!(i&(1<<(j-1)))) continue; int prev = i^(1<<(j-1)); if(dp[prev].s == -1) continue; int cur = dp[prev].s + bank[j], wanted = sal[dp[prev].f+1]; if(cur < wanted) dp[i] = {dp[prev].f, cur}; else if(cur == wanted) dp[i] = {dp[prev].f+1,0}; } } for(int i=1; i<=cs; i++){ if(dp[i].f == n){ printf("YES\n"); return 0; } } printf("NO\n"); }

Compilation message (stderr)

bank.cpp:9:25: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
    9 | pair<int,int> dp[1<<MAXN+5];
      |                     ~~~~^~
bank.cpp: In function 'int main()':
bank.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
bank.cpp:13:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for(int i=1; i<=n; i++) scanf("%d",&sal[i]);
      |                          ~~~~~^~~~~~~~~~~~~~
bank.cpp:14:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  for(int i=1; i<=m; i++) scanf("%d",&bank[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...