Submission #956132

#TimeUsernameProblemLanguageResultExecution timeMemory
956132Batorgil952Kitchen (BOI19_kitchen)C++14
100 / 100
81 ms107604 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int N=302; int a[N], b[N]; int dp[N][N*N]; int main(){ int n, m, k, i, j, s, ans, ind; scanf("%d",&n); scanf("%d",&m); scanf("%d",&k); s=0; ind=0; for(i=1; i<=n; i++){ scanf("%d",&a[i]); s+=a[i]; if(a[i]<k) ind++; } for(i=1; i<=m; i++){ scanf("%d",&b[i]); } if(ind!=0){ printf("Impossible\n"); return 0; } for(i=1; i<=m; i++){ for(j=1; j<=90000; j++){ dp[i][j]=dp[i-1][j]; if(j-b[i]>0 && dp[i-1][j-b[i]]>0){ dp[i][j]=max(dp[i][j], dp[i-1][j-b[i]]+min(n, b[i])); } else if(j-b[i]==0){ dp[i][j]=max(dp[i][j], min(n, b[i])); } } } ans=-1; for(i=1; i<=90000; i++){ if(dp[m][i]>=n*k && i>=s){ if(ans==-1) ans=i-s; else ans=min(ans, i-s); } } if(ans==-1) printf("Impossible\n"); else printf("%d\n", ans); return 0; }

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
kitchen.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d",&m);
      |  ~~~~~^~~~~~~~~
kitchen.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d",&k);
      |  ~~~~~^~~~~~~~~
kitchen.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d",&a[i]);
      |   ~~~~~^~~~~~~~~~~~
kitchen.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d",&b[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...
#Verdict Execution timeMemoryGrader output
Fetching results...