Submission #133036

#TimeUsernameProblemLanguageResultExecution timeMemory
133036E869120Kitchen (BOI19_kitchen)C++14
100 / 100
161 ms106488 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int N, M, K, S, A[1 << 18], B[1 << 18]; int dp[309][90009]; int solve_subtask5() { for (int i = 0; i <= M; i++) { for (int j = 0; j <= 90000; j++) dp[i][j] = -(1 << 30); } dp[0][0] = 0; for (int i = 0; i < M; i++) { for (int j = 0; j <= 90000; j++) { if (dp[i][j] == -(1 << 30)) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j + B[i]] = max(dp[i + 1][j + B[i]], dp[i][j] + min(B[i], N)); } } for (int i = S; i <= 90000; i++) { if (dp[M][i] >= N * K) return i - S; } return (1 << 30); } int main() { cin >> N >> M >> K; for (int i = 0; i < N; i++) { cin >> A[i]; S += A[i]; if (A[i] < K) { cout << "Impossible" << endl; return 0; } } for (int i = 0; i < M; i++) cin >> B[i]; int ans = solve_subtask5(); if (ans == (1 << 30)) cout << "Impossible" << endl; else cout << ans << endl; return 0; }
#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...