#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int maxsum = maxn * maxn;
const int inf = 1e9;
int n, m, k;
int a[maxn];
int b[maxn];
int dp[maxn][maxsum];
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
}
for (int i = 1; i <= m; ++i)
{
cin >> b[i];
}
for (int i = 1; i <= n; ++i)
{
if (a[i] < k)
{
cout << "Impossible" << endl;
return 0;
}
}
for (int i = 0; i < maxn; ++i)
{
for (int j = 0; j < maxsum; ++j)
{
dp[i][j] = -inf;
}
}
int sumB = 0;
for (int i = 1; i <= m; ++i)
{
sumB += b[i];
}
int sumA = 0;
for (int i = 1; i <= n; ++i)
{
sumA += a[i];
}
if (sumA > sumB)
{
cout << "Impossible" << endl;
return 0;
}
dp[0][0] = 0;
for (int pos = 1; pos <= m; ++pos)
{
for (int sum = 0; sum <= sumB; ++sum)
{
dp[pos][sum] = dp[pos - 1][sum];
if (sum >= b[pos])
{
dp[pos][sum] = max(dp[pos][sum], min(b[pos], n) + dp[pos - 1][sum - b[pos]]);
}
}
}
for (int i = sumA; i <= sumB; ++i)
{
if (dp[m][i] >= n * k)
{
cout << i - sumA << endl;
return 0;
}
}
cout << "Impossible" << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
111440 KB |
Output is correct |
2 |
Correct |
25 ms |
111452 KB |
Output is correct |
3 |
Correct |
25 ms |
111376 KB |
Output is correct |
4 |
Correct |
25 ms |
111268 KB |
Output is correct |
5 |
Correct |
25 ms |
111352 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
30 ms |
111444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
111440 KB |
Output is correct |
2 |
Correct |
25 ms |
111452 KB |
Output is correct |
3 |
Correct |
25 ms |
111376 KB |
Output is correct |
4 |
Correct |
25 ms |
111268 KB |
Output is correct |
5 |
Correct |
25 ms |
111352 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
30 ms |
111444 KB |
Output is correct |
9 |
Correct |
26 ms |
111452 KB |
Output is correct |
10 |
Correct |
26 ms |
111352 KB |
Output is correct |
11 |
Correct |
25 ms |
111444 KB |
Output is correct |
12 |
Correct |
25 ms |
111452 KB |
Output is correct |
13 |
Correct |
25 ms |
111452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
111440 KB |
Output is correct |
2 |
Correct |
49 ms |
111452 KB |
Output is correct |
3 |
Correct |
51 ms |
111424 KB |
Output is correct |
4 |
Correct |
60 ms |
111484 KB |
Output is correct |
5 |
Correct |
25 ms |
111452 KB |
Output is correct |
6 |
Correct |
39 ms |
111480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
111324 KB |
Output is correct |
2 |
Correct |
25 ms |
111444 KB |
Output is correct |
3 |
Correct |
25 ms |
111452 KB |
Output is correct |
4 |
Correct |
25 ms |
111260 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
111440 KB |
Output is correct |
2 |
Correct |
25 ms |
111452 KB |
Output is correct |
3 |
Correct |
25 ms |
111376 KB |
Output is correct |
4 |
Correct |
25 ms |
111268 KB |
Output is correct |
5 |
Correct |
25 ms |
111352 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
30 ms |
111444 KB |
Output is correct |
9 |
Correct |
26 ms |
111452 KB |
Output is correct |
10 |
Correct |
26 ms |
111352 KB |
Output is correct |
11 |
Correct |
25 ms |
111444 KB |
Output is correct |
12 |
Correct |
25 ms |
111452 KB |
Output is correct |
13 |
Correct |
25 ms |
111452 KB |
Output is correct |
14 |
Correct |
50 ms |
111440 KB |
Output is correct |
15 |
Correct |
49 ms |
111452 KB |
Output is correct |
16 |
Correct |
51 ms |
111424 KB |
Output is correct |
17 |
Correct |
60 ms |
111484 KB |
Output is correct |
18 |
Correct |
25 ms |
111452 KB |
Output is correct |
19 |
Correct |
39 ms |
111480 KB |
Output is correct |
20 |
Correct |
26 ms |
111324 KB |
Output is correct |
21 |
Correct |
25 ms |
111444 KB |
Output is correct |
22 |
Correct |
25 ms |
111452 KB |
Output is correct |
23 |
Correct |
25 ms |
111260 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
49 ms |
111488 KB |
Output is correct |
26 |
Correct |
47 ms |
111452 KB |
Output is correct |
27 |
Correct |
32 ms |
111416 KB |
Output is correct |
28 |
Correct |
50 ms |
111444 KB |
Output is correct |
29 |
Correct |
52 ms |
111696 KB |
Output is correct |
30 |
Correct |
68 ms |
111488 KB |
Output is correct |