#include <bits/stdc++.h>
using namespace std;
#define int long long
const int lim = 1e18;
int n, m, k;
int sum = 0, need = 0;
int dp[100005], a[1005], b[1005];
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];
        need += a[i];
        if (a[i] < k) 
		{
            cout << "Impossible";
            return 0;
        }
    }
    int good = 0;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        sum += min(b[i], n);
        good += b[i];
    }
    if (sum < n * k) {
        cout << "Impossible";
        return 0;
    }
    const int inf = -lim;
    dp[0] = 0;
    for (int t = 1; t <= good; t++) 
	{
        dp[t] = inf;
    }
    for (int i = 1; i <= m; i++)
	{
        int c = min(b[i], n);
        for (int t = good; t >= b[i]; t--) 
		{
            if (dp[t - b[i]] != inf) 
			{
                dp[t] = max(dp[t], dp[t - b[i]] + c);
            }
        }
    }
    int ans = lim;
    for (int t = need; t <= good; t++) 
	{
        if (dp[t] >= n * k) 
		{
            ans = min(ans, t - need);
        }
    }
    if (ans == lim)  cout << "Impossible";
    else  cout << ans;
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |