제출 #1135141

#제출 시각아이디문제언어결과실행 시간메모리
1135141SofiatpcKitchen (BOI19_kitchen)C++20
100 / 100
67 ms100420 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 305, INF = 1e9; int a[MAXN], b[MAXN], dp[MAXN][MAXN*MAXN]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,k; cin>>n>>m>>k; int sa = 0; for(int i = 1; i <= n; i++){ cin>>a[i]; sa += a[i]; } int sb = 0; for(int i = 1; i <= m; i++){ cin>>b[i]; sb += b[i]; } for(int i = 1; i <= n; i++) if(a[i] < k){ cout<<"Impossible\n"; return 0; } for(int j = 1; j <= sb; j++) dp[0][j] = -INF; for(int i = 1; i <= m; i++) for(int j = 1; j <= sb; j++){ dp[i][j] = dp[i-1][j]; if(j >= b[i])dp[i][j] = max(dp[i-1][j], dp[i-1][j - b[i]] + min(b[i],n)); } for(int j = sa; j <= sb; j++) if(dp[m][j] >= n*k){ cout<<j-sa<<"\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...