#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 |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12756 KB |
Output is correct |
11 |
Correct |
2 ms |
12776 KB |
Output is correct |
12 |
Correct |
2 ms |
12756 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
151768 KB |
Output is correct |
2 |
Correct |
54 ms |
122212 KB |
Output is correct |
3 |
Correct |
62 ms |
140884 KB |
Output is correct |
4 |
Correct |
103 ms |
200788 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
41 ms |
107100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29272 KB |
Output is correct |
2 |
Correct |
3 ms |
29020 KB |
Output is correct |
3 |
Correct |
3 ms |
29092 KB |
Output is correct |
4 |
Correct |
3 ms |
29020 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
12636 KB |
Output is correct |
10 |
Correct |
2 ms |
12756 KB |
Output is correct |
11 |
Correct |
2 ms |
12776 KB |
Output is correct |
12 |
Correct |
2 ms |
12756 KB |
Output is correct |
13 |
Correct |
2 ms |
12636 KB |
Output is correct |
14 |
Correct |
77 ms |
151768 KB |
Output is correct |
15 |
Correct |
54 ms |
122212 KB |
Output is correct |
16 |
Correct |
62 ms |
140884 KB |
Output is correct |
17 |
Correct |
103 ms |
200788 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
41 ms |
107100 KB |
Output is correct |
20 |
Correct |
4 ms |
29272 KB |
Output is correct |
21 |
Correct |
3 ms |
29020 KB |
Output is correct |
22 |
Correct |
3 ms |
29092 KB |
Output is correct |
23 |
Correct |
3 ms |
29020 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
56 ms |
116716 KB |
Output is correct |
26 |
Correct |
69 ms |
138184 KB |
Output is correct |
27 |
Correct |
22 ms |
70744 KB |
Output is correct |
28 |
Correct |
48 ms |
122508 KB |
Output is correct |
29 |
Correct |
76 ms |
150180 KB |
Output is correct |
30 |
Correct |
103 ms |
202900 KB |
Output is correct |