#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;
}
}
F[0][0] = 0;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
68944 KB |
Output is correct |
2 |
Correct |
36 ms |
51800 KB |
Output is correct |
3 |
Correct |
43 ms |
58348 KB |
Output is correct |
4 |
Correct |
66 ms |
98816 KB |
Output is correct |
5 |
Correct |
70 ms |
98896 KB |
Output is correct |
6 |
Correct |
27 ms |
42332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
64 ms |
68944 KB |
Output is correct |
15 |
Correct |
36 ms |
51800 KB |
Output is correct |
16 |
Correct |
43 ms |
58348 KB |
Output is correct |
17 |
Correct |
66 ms |
98816 KB |
Output is correct |
18 |
Correct |
70 ms |
98896 KB |
Output is correct |
19 |
Correct |
27 ms |
42332 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
34 ms |
50524 KB |
Output is correct |
26 |
Correct |
41 ms |
62608 KB |
Output is correct |
27 |
Correct |
13 ms |
19036 KB |
Output is correct |
28 |
Correct |
39 ms |
51548 KB |
Output is correct |
29 |
Correct |
49 ms |
70236 KB |
Output is correct |
30 |
Correct |
78 ms |
100548 KB |
Output is correct |