#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)
{
cout << "Impossible";
return;
}
}
for (int x = 1; x <= m; x++)
{
sumb += b[x];
}
for (int x = 1; x <= m; x++)
{
for (int y = 0; y < b[x]; y++)
{
F[x][y] = F[x - 1][y];
}
for (int y = b[x]; y <= sumb; y++)
{
F[x][y] = max(F[x - 1][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 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
68652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
720 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |