#include <bits/stdc++.h>
#define ll int
using namespace std;
#define bit(x,y) ((x >> y) & 1)
const ll mod = 1e9 + 7;
const ll inf = INT_MIN/2;
ll d[305][305 * 305];
ll a[305],b[305];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,m,k;
cin >> n >> m >> k;
ll i,j;
ll s = 0;
for(i = 1;i <= n;i++)
{
cin >> a[i];
s += a[i];
}
for(i = 1;i <= m;i++) cin >> b[i];
for(i = 1;i <= n;i++)
{
if(a[i] < k)
{
cout << "Impossible";
return 0;
}
}
for(i = 0;i <= 300;i++)
{
for(j = 0;j <= 300 * 300;j++)
{
d[i][j] = inf;
}
}
d[0][0] = 0;
for(i = 1;i <= m;i++)
{
for(j = 0;j <= 300 * 300;j++)
{
if(d[i - 1][j] == inf) continue;
d[i][j] = max(d[i][j],d[i - 1][j]);
if(j + b[i] <= 300 * 300) d[i][j + b[i]] = max(d[i][j + b[i]],d[i - 1][j] + min(b[i],n));
}
}
ll ans = -1;
for(i = s;i <= 300 * 300;i++)
{
if(d[m][i] >= n * k)
{
ans = i - s;
break;
}
}
if(ans == -1) cout << "Impossible";
else cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
108628 KB |
Output is correct |
2 |
Correct |
38 ms |
108632 KB |
Output is correct |
3 |
Correct |
38 ms |
108628 KB |
Output is correct |
4 |
Correct |
41 ms |
108624 KB |
Output is correct |
5 |
Correct |
37 ms |
108628 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
108540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
108628 KB |
Output is correct |
2 |
Correct |
38 ms |
108632 KB |
Output is correct |
3 |
Correct |
38 ms |
108628 KB |
Output is correct |
4 |
Correct |
41 ms |
108624 KB |
Output is correct |
5 |
Correct |
37 ms |
108628 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
108540 KB |
Output is correct |
9 |
Correct |
37 ms |
108628 KB |
Output is correct |
10 |
Correct |
39 ms |
108464 KB |
Output is correct |
11 |
Correct |
39 ms |
108624 KB |
Output is correct |
12 |
Correct |
38 ms |
108408 KB |
Output is correct |
13 |
Correct |
39 ms |
108636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
108648 KB |
Output is correct |
2 |
Correct |
65 ms |
108624 KB |
Output is correct |
3 |
Correct |
65 ms |
108620 KB |
Output is correct |
4 |
Correct |
67 ms |
108636 KB |
Output is correct |
5 |
Correct |
72 ms |
108636 KB |
Output is correct |
6 |
Correct |
54 ms |
108428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
108624 KB |
Output is correct |
2 |
Correct |
42 ms |
108560 KB |
Output is correct |
3 |
Correct |
42 ms |
108628 KB |
Output is correct |
4 |
Correct |
40 ms |
108584 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
108628 KB |
Output is correct |
2 |
Correct |
38 ms |
108632 KB |
Output is correct |
3 |
Correct |
38 ms |
108628 KB |
Output is correct |
4 |
Correct |
41 ms |
108624 KB |
Output is correct |
5 |
Correct |
37 ms |
108628 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
108540 KB |
Output is correct |
9 |
Correct |
37 ms |
108628 KB |
Output is correct |
10 |
Correct |
39 ms |
108464 KB |
Output is correct |
11 |
Correct |
39 ms |
108624 KB |
Output is correct |
12 |
Correct |
38 ms |
108408 KB |
Output is correct |
13 |
Correct |
39 ms |
108636 KB |
Output is correct |
14 |
Correct |
62 ms |
108648 KB |
Output is correct |
15 |
Correct |
65 ms |
108624 KB |
Output is correct |
16 |
Correct |
65 ms |
108620 KB |
Output is correct |
17 |
Correct |
67 ms |
108636 KB |
Output is correct |
18 |
Correct |
72 ms |
108636 KB |
Output is correct |
19 |
Correct |
54 ms |
108428 KB |
Output is correct |
20 |
Correct |
40 ms |
108624 KB |
Output is correct |
21 |
Correct |
42 ms |
108560 KB |
Output is correct |
22 |
Correct |
42 ms |
108628 KB |
Output is correct |
23 |
Correct |
40 ms |
108584 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
59 ms |
108468 KB |
Output is correct |
26 |
Correct |
59 ms |
108624 KB |
Output is correct |
27 |
Correct |
52 ms |
108644 KB |
Output is correct |
28 |
Correct |
60 ms |
108464 KB |
Output is correct |
29 |
Correct |
63 ms |
108628 KB |
Output is correct |
30 |
Correct |
72 ms |
108504 KB |
Output is correct |