#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
//#define ld long double
using namespace std;
using ll=long long;
const int inf = 2e18;
const int MN = 305;
const int mod=1e9+7;
int n,m,k;
int a[MN],b[MN];
int dp[MN][MN*MN];
int mx,sum;
inline void solve() {
cin>>n>>m>>k;
for (int i=1; i<=n; i++) {
cin>>a[i];
mx+=a[i];
}
for (int i=1; i<=m; i++) {
cin>>b[i];
sum+=b[i];
}
for (int i=1; i<=n; i++) {
if(a[i]<k) {
cout<<"Impossible";
return;
}
}
for (int i=1; i<=sum; i++) {
dp[0][i]=-inf;
}
for (int i=1; i<=m; i++) {
for (int w=sum; w>=0; w--) {
dp[i][w]=dp[i-1][w];
if(w+b[i]<=sum) dp[i][w+b[i]]=max(dp[i][w+b[i]],dp[i-1][w]+min(b[i],n));
}
}
for (int i=mx; i<=sum; i++) {
if(dp[m][i]>=n*k) {
cout<<i-mx;
return;
}
}
cout<<"Impossible";
// cout<<mn;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#define task "A"
if(fopen(task".inp", "r"))
{
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
}
int t=1;
// preprocess();
// cin>>t;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
136596 KB |
Output is correct |
2 |
Correct |
42 ms |
102180 KB |
Output is correct |
3 |
Correct |
48 ms |
114864 KB |
Output is correct |
4 |
Correct |
81 ms |
195848 KB |
Output is correct |
5 |
Correct |
81 ms |
196232 KB |
Output is correct |
6 |
Correct |
41 ms |
83132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
56 ms |
136596 KB |
Output is correct |
15 |
Correct |
42 ms |
102180 KB |
Output is correct |
16 |
Correct |
48 ms |
114864 KB |
Output is correct |
17 |
Correct |
81 ms |
195848 KB |
Output is correct |
18 |
Correct |
81 ms |
196232 KB |
Output is correct |
19 |
Correct |
41 ms |
83132 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
852 KB |
Output is correct |
23 |
Correct |
1 ms |
980 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
41 ms |
99916 KB |
Output is correct |
26 |
Correct |
51 ms |
123764 KB |
Output is correct |
27 |
Correct |
17 ms |
37164 KB |
Output is correct |
28 |
Correct |
43 ms |
101580 KB |
Output is correct |
29 |
Correct |
57 ms |
138956 KB |
Output is correct |
30 |
Correct |
84 ms |
199280 KB |
Output is correct |