Submission #329201

#TimeUsernameProblemLanguageResultExecution timeMemory
329201Mahdi_ShokoufiKitchen (BOI19_kitchen)C++17
100 / 100
112 ms109696 KiB
//In The Name of Allah #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair < int , int > pii; typedef pair < ll , ll > pll; #define X first #define Y second #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x.size()) const int N = 300 + 10; const int M = 90000 + 10; const ll mod = 1e9 + 7; const int inf = 1e9 + 10; int a[N], b[N], dp[N][M]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int sum = 0, mn = inf; for (int i = 1; i <= n; i ++) cin >> a[i], sum += a[i], mn = min(mn, a[i]); for (int i = 1; i <= m; i ++) cin >> b[i]; if (mn < k) return cout << "Impossible", 0; for (int i = 0; i < N; i ++) for (int j = 0; j < M; j ++) dp[i][j] = -inf; dp[0][0] = 0; for (int i = 1; i <= m; i ++){ for (int j = 0; j < M; j ++){ dp[i][j] = dp[i - 1][j]; if (b[i] <= j && dp[i - 1][j - b[i]] != -inf) dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(b[i], n)); } } int ans = inf; for (int j = sum; j < M; j ++) if (n * k <= dp[m][j]) ans = min(ans, j - sum); if (ans == inf) return cout << "Impossible", 0; cout << ans; 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...