#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
int dp[90001];
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
int a[n];
int b[m];
for(auto &i:a)cin>>i;
for(auto &i:b)cin>>i;
if(m<k){cout<<"Impossible";return 0;}
for(int i=0;i<n;i++){
if(a[i]<k){cout<<"Impossible";return 0;}
}
memset(dp,-1,sizeof dp);
dp[0]=0;
for(int i=0;i<m;i++){
for(int j=90000-b[i];j>=0;j--){
if(dp[j]!=-1)dp[j+b[i]]=max(dp[j+b[i]],dp[j]+min(b[i],n));
}
}
int sm=0;
int ans=INT_MAX;
for(auto &i:a)sm+=i;
// for(int i=k;i<=m;i++){
for(int w=sm;w<=90000;w++){
if(dp[w]>=n*k){
ans=min(ans,w-sm);
}
}
// }
if(ans==INT_MAX)cout<<"Impossible";
else cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
596 KB |
Output is correct |
2 |
Correct |
23 ms |
680 KB |
Output is correct |
3 |
Correct |
34 ms |
656 KB |
Output is correct |
4 |
Correct |
34 ms |
656 KB |
Output is correct |
5 |
Correct |
30 ms |
660 KB |
Output is correct |
6 |
Correct |
22 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
9 ms |
672 KB |
Output is correct |
3 |
Correct |
5 ms |
588 KB |
Output is correct |
4 |
Correct |
7 ms |
584 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
30 ms |
596 KB |
Output is correct |
15 |
Correct |
23 ms |
680 KB |
Output is correct |
16 |
Correct |
34 ms |
656 KB |
Output is correct |
17 |
Correct |
34 ms |
656 KB |
Output is correct |
18 |
Correct |
30 ms |
660 KB |
Output is correct |
19 |
Correct |
22 ms |
596 KB |
Output is correct |
20 |
Correct |
4 ms |
596 KB |
Output is correct |
21 |
Correct |
9 ms |
672 KB |
Output is correct |
22 |
Correct |
5 ms |
588 KB |
Output is correct |
23 |
Correct |
7 ms |
584 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
20 ms |
596 KB |
Output is correct |
26 |
Correct |
28 ms |
596 KB |
Output is correct |
27 |
Correct |
17 ms |
596 KB |
Output is correct |
28 |
Correct |
26 ms |
596 KB |
Output is correct |
29 |
Correct |
29 ms |
596 KB |
Output is correct |
30 |
Correct |
33 ms |
596 KB |
Output is correct |