This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const ll maxn = 302, LG = 21, mod = 998244353, inf = 1e18;
ll n, m, k, a[maxn], b[maxn], req = 0, tot = 0, dp[maxn][maxn*maxn];
int main ()
{
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
req += a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> b[i];
tot += b[i];
}
if (m < k || tot < req)
{
cout << "Impossible";
return 0;
}
for (int i = 1; i <= n; i++)
if (a[i] < k)
{
cout << "Impossible";
return 0;
}
for (int i = 0; i <= m; i++)
for (int j = 0; j <= tot; j++) dp[i][j] = -1;
dp[0][0] = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j <= tot; j++)
{
if (dp[i][j] == -1) continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (j + b[i + 1] <= tot) dp[i + 1][j + b[i + 1]] = max(dp[i + 1][j + b[i + 1]], dp[i][j] + min(b[i + 1], n));
}
for (int i = req; i <= tot; i++)
if (dp[m][i] >= n*k)
{
cout << i - req;
return 0;
}
cout << "Impossible";
}
# | 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... |