#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MaxN = 3e2 + 5;
int n, m, k;
int a[MaxN];
int b[MaxN];
void Inp()
{
cin >> n >> m >> k;
for (int x = 1; x <= n; x++)
{
cin >> a[x];
}
for (int x = 1; x <= m; x++)
{
cin >> b[x];
}
}
int F[MaxN][MaxN * MaxN + 5];
void Exc()
{
int suma = 0, sumb = 0;
for (int x = 1; x <= n; x++)
{
suma += a[x];
if (a[x] < k || m < k)
{
cout << "Impossible";
return;
}
}
for (int x = 1; x <= m; x++)
{
sumb += b[x];
}
for (int x = 0; x <= m; x++)
{
for (int y = 0; y <= sumb; y++)
{
F[x][y] = -1;
}
}
for (int x = 1; x <= m; x++)
{
for (int y = 0; y < b[x]; y++)
{
if (F[x - 1][y] != -1)
{
F[x][y] = F[x - 1][y];
}
}
for (int y = b[x]; y <= sumb; y++)
{
if (F[x - 1][y] != -1)
{
F[x][y] = F[x - 1][y];
}
if (F[x - 1][y - b[x]] != -1)
{
F[x][y] = max(F[x][y], F[x - 1][y - b[x]] + min(b[x], n));
}
}
}
for (int x = suma; x <= sumb; x++)
{
if (F[m][x] >= n * k)
{
cout << x - suma;
return;
}
}
cout << "Impossible";
}
int main()
{
//freopen("F.INP", "r", stdin);
//freopen("F.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test = 1;
//cin >> test;
for (int x = 1; x <= test; x++)
{
Inp();
Exc();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
68956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |