Submission #1220076

#TimeUsernameProblemLanguageResultExecution timeMemory
1220076jellybeanKitchen (BOI19_kitchen)C++20
0 / 100
113 ms211800 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second typedef pair<int,int> pii; const int N = 305, M = 305; int dp[M][90005], a[N], b[M]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m,k; cin>>n>>m>>k; int tot = 0; for(int i=1; i<=n; i++) cin>>a[i], tot+=a[i]; for(int i=1; i<=m; i++) cin>>b[i]; dp[0][0] = 1; for(int i=1; i<=m; i++){ for(int j=0; j<=90005; j++){ if(dp[i-1][j]) dp[i][j] = 1; else if(j-b[i] >= 0) dp[i][j] = dp[i-1][j-b[i]]; } } int ans = -1; for(int i=tot; i<=90005; i++){ if(dp[m][i]) {ans = i-tot; break;} } if(ans == -1) cout<<"Impossible"; else cout<<ans; return 0; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:23:37: warning: iteration 90005 invokes undefined behavior [-Waggressive-loop-optimizations]
   23 |                         if(dp[i-1][j]) dp[i][j] = 1;
      |                            ~~~~~~~~~^
kitchen.cpp:22:31: note: within this loop
   22 |                 for(int j=0; j<=90005; j++){
      |                              ~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...