#include <bits/stdc++.h>
#define DIM 310
#define INF 2000000000
using namespace std;
int a[DIM],b[DIM],dp[2][DIM*DIM];
int n,m,k,i,j,sum_a,sum_b,t,ok;
int main (){
cin>>n>>m>>k;
for (i=1;i<=n;i++){
cin>>a[i];
if (a[i] < k)
ok = 1;
sum_a += a[i];
}
for (i=1;i<=m;i++){
cin>>b[i];
sum_b += b[i];
}
if (ok || sum_b < sum_a){
cout<<"Impossible";
return 0;
}
sort (b+1,b+m+1);
/// trb sa am minim k bucatari diferiti pt fiecare masa
/// dp[i][j] - nr maxim de zone pe care pot sa le acopar cu primii i bucatari si in total sa platesc j
for (j=0;j<=sum_b;j++)
dp[0][j] = -INF;
dp[0][0] = 0;
t = 1;
for (i=1;i<=m;i++){
for (j=0;j<=sum_b;j++)
dp[t][j] = -INF;
for (j=0;j<=sum_b;j++){
if (j < b[i]){
dp[t][j] = dp[1-t][j];
continue;
}
if (dp[1-t][j-b[i]] != -INF)
dp[t][j] = max (dp[1-t][j],dp[1-t][j-b[i]] + min(n,b[i]));
else dp[t][j] = dp[1-t][j];
}
t = 1-t;
}
for (j=sum_a;j<=sum_b;j++){
if (dp[1-t][j] >= n*k){
cout<<j-sum_a;
return 0;
}
}
cout<<"Impossible";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
888 KB |
Output is correct |
2 |
Correct |
28 ms |
760 KB |
Output is correct |
3 |
Correct |
31 ms |
760 KB |
Output is correct |
4 |
Correct |
53 ms |
1144 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
24 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
35 ms |
888 KB |
Output is correct |
15 |
Correct |
28 ms |
760 KB |
Output is correct |
16 |
Correct |
31 ms |
760 KB |
Output is correct |
17 |
Correct |
53 ms |
1144 KB |
Output is correct |
18 |
Correct |
4 ms |
376 KB |
Output is correct |
19 |
Correct |
24 ms |
760 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
26 ms |
860 KB |
Output is correct |
26 |
Correct |
37 ms |
892 KB |
Output is correct |
27 |
Correct |
11 ms |
604 KB |
Output is correct |
28 |
Correct |
28 ms |
764 KB |
Output is correct |
29 |
Correct |
38 ms |
888 KB |
Output is correct |
30 |
Correct |
54 ms |
1016 KB |
Output is correct |