-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17186.cpp
More file actions
43 lines (39 loc) · 932 Bytes
/
17186.cpp
File metadata and controls
43 lines (39 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
using namespace std;
const ll INF = 1e9 + 7;
const ll DIV = 987654321;
int n,m, k;
int A[303], B[303];
int dp[101010];
int main()
{
fastio;
cin >> n >> m >> k;
int tot = 0;
for(int i =1 ;i <= n;i++) cin >> A[i], tot += A[i];
for(int i = 1;i<=m;i++) cin >> B[i];
for(int i = 1;i<=n;i++){
if(A[i] < k){
cout << "Impossible\n";
return 0;
}
}
fill(dp, dp + 100011, -INF);
dp[0]= 0;
for(int i = 1;i<=m;i++){
for(int j = 100000;j>0;j--){
if(j >= B[i])
dp[j] = max(dp[j], dp[j - B[i]]+min(B[i], n));
}
}
for(int i = tot;i<=100000;i++){
if(dp[i] >= n * k){
cout << i - tot << "\n";
return 0;
}
}
cout << "Impossible\n";
return 0;
}