#include <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define maxn 310
int inf=1000000000;
int a[310],b[310];
int dp[310][maxn*maxn];
///identican kod al dzaba
int main()
{
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int n,m,k;
int mealsum=0,sum=0;
bool is=true;
cin>>n>>m>>k;
for( int i=1;i<=n;i++ ) {
cin>>a[i];
if( a[i] < k ){
is=false;
// return 0;
}
mealsum+=a[i];
}
for( int i=1;i<=m;i++ ){
cin>>b[i];
sum+=b[i];
}
if(!is){
cout << "Impossible" <<endl;
return 0;
}
sum = 305*305;
for( int i=0;i<=m;i++ ){
for( int j=0;j<=sum;j++ ) dp[i][j]=-inf;
}
dp[0][0]=0;
for( int i=1;i<=m;i++ ){
for( int j=0;j<=sum;j++ ){
if( j - b[i] >=0 )
dp[i][j] = max( dp[i-1][j], dp[i-1][ j - b[i] ] + min( n,b[i] ) );
else dp[i][j]=dp[i-1][j];
}
}
for( int i = mealsum;i<= sum;i++ ){
if( dp[m][i] >= n*k ){
cout << i - mealsum << endl;
return 0;
}
}
cout << "Impossible" <<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1404 KB |
Output is correct |
3 |
Correct |
3 ms |
1400 KB |
Output is correct |
4 |
Correct |
3 ms |
1400 KB |
Output is correct |
5 |
Correct |
3 ms |
1400 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
1404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1404 KB |
Output is correct |
3 |
Correct |
3 ms |
1400 KB |
Output is correct |
4 |
Correct |
3 ms |
1400 KB |
Output is correct |
5 |
Correct |
3 ms |
1400 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
1404 KB |
Output is correct |
9 |
Correct |
9 ms |
6136 KB |
Output is correct |
10 |
Correct |
9 ms |
6264 KB |
Output is correct |
11 |
Correct |
9 ms |
6264 KB |
Output is correct |
12 |
Correct |
9 ms |
6264 KB |
Output is correct |
13 |
Correct |
9 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
96692 KB |
Output is correct |
2 |
Correct |
99 ms |
83888 KB |
Output is correct |
3 |
Correct |
132 ms |
111184 KB |
Output is correct |
4 |
Correct |
130 ms |
111068 KB |
Output is correct |
5 |
Correct |
133 ms |
107436 KB |
Output is correct |
6 |
Correct |
92 ms |
77304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
15480 KB |
Output is correct |
2 |
Correct |
20 ms |
15352 KB |
Output is correct |
3 |
Correct |
19 ms |
15352 KB |
Output is correct |
4 |
Correct |
20 ms |
15484 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1400 KB |
Output is correct |
2 |
Correct |
3 ms |
1404 KB |
Output is correct |
3 |
Correct |
3 ms |
1400 KB |
Output is correct |
4 |
Correct |
3 ms |
1400 KB |
Output is correct |
5 |
Correct |
3 ms |
1400 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
1404 KB |
Output is correct |
9 |
Correct |
9 ms |
6136 KB |
Output is correct |
10 |
Correct |
9 ms |
6264 KB |
Output is correct |
11 |
Correct |
9 ms |
6264 KB |
Output is correct |
12 |
Correct |
9 ms |
6264 KB |
Output is correct |
13 |
Correct |
9 ms |
6264 KB |
Output is correct |
14 |
Correct |
113 ms |
96692 KB |
Output is correct |
15 |
Correct |
99 ms |
83888 KB |
Output is correct |
16 |
Correct |
132 ms |
111184 KB |
Output is correct |
17 |
Correct |
130 ms |
111068 KB |
Output is correct |
18 |
Correct |
133 ms |
107436 KB |
Output is correct |
19 |
Correct |
92 ms |
77304 KB |
Output is correct |
20 |
Correct |
20 ms |
15480 KB |
Output is correct |
21 |
Correct |
20 ms |
15352 KB |
Output is correct |
22 |
Correct |
19 ms |
15352 KB |
Output is correct |
23 |
Correct |
20 ms |
15484 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
92 ms |
78072 KB |
Output is correct |
26 |
Correct |
107 ms |
90280 KB |
Output is correct |
27 |
Correct |
72 ms |
59576 KB |
Output is correct |
28 |
Correct |
107 ms |
90488 KB |
Output is correct |
29 |
Correct |
110 ms |
92828 KB |
Output is correct |
30 |
Correct |
130 ms |
111096 KB |
Output is correct |