#include <bits/stdc++.h>
using namespace std;
long long a[305], b[305], dp[90005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long n, m, k, i, j, check=1;
cin >> n >> m >> k;
for (i=1; i<=n; i++) {cin >> a[i]; if (a[i]<k) {check=0;}; a[i]+=a[i-1];};
dp[0]=0;
for (i=1; i<=90000; i++) {dp[i]=-1;};
for (i=1; i<=m; i++)
{
cin >> b[i];
for (j=90000; j>=b[i]; j--)
{
if (dp[j-b[i]]!=-1) {dp[j]=max(dp[j], dp[j-b[i]]+min(n, b[i]));};
};
};
for (i=a[n]; i<=90000; i++)
{
if (dp[i]>=n*k) {break;};
};
if (check==0 || i==90001) {cout << "Impossible";}
else {cout << i-a[n];};
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1116 KB |
Output is correct |
2 |
Correct |
14 ms |
1112 KB |
Output is correct |
3 |
Correct |
23 ms |
1172 KB |
Output is correct |
4 |
Correct |
18 ms |
1168 KB |
Output is correct |
5 |
Correct |
18 ms |
1116 KB |
Output is correct |
6 |
Correct |
14 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
3 ms |
1116 KB |
Output is correct |
5 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
17 ms |
1116 KB |
Output is correct |
15 |
Correct |
14 ms |
1112 KB |
Output is correct |
16 |
Correct |
23 ms |
1172 KB |
Output is correct |
17 |
Correct |
18 ms |
1168 KB |
Output is correct |
18 |
Correct |
18 ms |
1116 KB |
Output is correct |
19 |
Correct |
14 ms |
1116 KB |
Output is correct |
20 |
Correct |
3 ms |
1116 KB |
Output is correct |
21 |
Correct |
3 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
1116 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1116 KB |
Output is correct |
25 |
Correct |
13 ms |
1116 KB |
Output is correct |
26 |
Correct |
16 ms |
1116 KB |
Output is correct |
27 |
Correct |
10 ms |
1116 KB |
Output is correct |
28 |
Correct |
15 ms |
1112 KB |
Output is correct |
29 |
Correct |
16 ms |
1164 KB |
Output is correct |
30 |
Correct |
18 ms |
1172 KB |
Output is correct |