Submission #602825

#TimeUsernameProblemLanguageResultExecution timeMemory
602825WongChun1234Kitchen (BOI19_kitchen)C++14
100 / 100
101 ms118160 KiB
#include<bits/stdc++.h> using namespace std; const int N=350,M=100050; int n,m,k,a[N],b[N],dp[N][M],sum; int main(){ cin>>n>>m>>k; for (int i=1;i<=n;i++) { cin>>a[i]; if (a[i]<k){ cout<<"Impossible\n"; return 0; } sum+=a[i]; } for (int i=1;i<=m;i++) cin>>b[i]; for (int i=0;i<=m;i++) for (int j=0;j<M;j++) dp[i][j]=INT_MIN; dp[0][0]=0; for (int i=1;i<=m;i++) for (int j=0;j<M;j++){ if (j<b[i]) dp[i][j]=dp[i-1][j]; else if (b[i]>n) dp[i][j]=max(dp[i-1][j],dp[i-1][j-b[i]]+n); else dp[i][j]=max(dp[i-1][j],dp[i-1][j-b[i]]+b[i]); } for (int j=sum;j<M;j++){ if (dp[m][j]>=n*k){ cout<<j-sum<<"\n"; return 0; } } cout<<"Impossible\n"; }
#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...