제출 #1304138

#제출 시각아이디문제언어결과실행 시간메모리
1304138nathlol2Kitchen (BOI19_kitchen)C++20
100 / 100
111 ms144964 KiB
#include <bits/stdc++.h> using namespace std; const int N = 333; int n, m, k, sm, cc, ans = INT_MAX, a[N], b[N], dp[N][N * N]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; for(int i = 1;i<=n;i++) cin >> a[i], sm += a[i], cc |= (a[i] < k); for(int i = 1;i<=m;i++) cin >> b[i]; if(cc) return cout << "Impossible", 0; for(int i = 0;i<N;i++) for(int j = 0;j<N*N;j++) dp[i][j] = INT_MIN; dp[0][0] = 0; for(int i = 1;i<=m;i++){ memcpy(dp[i], dp[i - 1], sizeof dp[i]); for(int j = 0;j + b[i]<N*N;j++){ dp[i][j + b[i]] = max(dp[i][j + b[i]], dp[i - 1][j] + min(n, b[i])); if(dp[i][j + b[i]] >= n * k && j + b[i] >= sm) ans = min(ans, j + b[i] - sm); } } if(ans == INT_MAX) cout << "Impossible"; else cout << ans; }
#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...