#include <bits/stdc++.h>
//#pra
#define sz(x) (int)x.size()
#define vec vector
#define pb push_back
using namespace std;
const int N=3e2+3;
auto rnd=bind(uniform_int_distribution<int>(1,5),mt19937(time(0)));
int dp[N*N];
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=0;i<2;i++){
fill(dp,dp+N*N,-1e9);
}
vec<int>a(n),b(m);
int sm=0;
for(auto &z : a ) cin>>z,sm+=z;
for(auto &z : b) cin>>z;
for(int i=0;i<n;i++){
if(a[i]<k){
cout<<"Impossible";
return 0;
}
}
sort(b.rbegin(),b.rend());
dp[0]=0;
int ans=2e9;
for(int i=0;i<=m;i++){
for(int s=N*N-1;s>=0;s--){
if(i!=m && s+b[i]<N*N)dp[s+b[i]]=max(dp[s+b[i]],dp[s]+min(b[i],n));
// cerr<<s<<' '<<dp[0][s]<<endl;
if(s>=sm && dp[s]>=n*k){
// cout<<i;
ans=min(ans,s-sm);
// cerr<<dp[1][s]<<' '<<s<<endl;
// return 0;
}
}
// swap(dp[0],dp[1]);
}
if(ans==2e9)
cout<<"Impossible";
else cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
7 ms |
680 KB |
Output is correct |
10 |
Correct |
7 ms |
584 KB |
Output is correct |
11 |
Correct |
7 ms |
688 KB |
Output is correct |
12 |
Correct |
7 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
676 KB |
Output is correct |
2 |
Correct |
85 ms |
664 KB |
Output is correct |
3 |
Correct |
113 ms |
584 KB |
Output is correct |
4 |
Correct |
110 ms |
588 KB |
Output is correct |
5 |
Correct |
104 ms |
672 KB |
Output is correct |
6 |
Correct |
77 ms |
664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
588 KB |
Output is correct |
2 |
Correct |
16 ms |
688 KB |
Output is correct |
3 |
Correct |
16 ms |
584 KB |
Output is correct |
4 |
Correct |
19 ms |
688 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
640 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
7 ms |
680 KB |
Output is correct |
10 |
Correct |
7 ms |
584 KB |
Output is correct |
11 |
Correct |
7 ms |
688 KB |
Output is correct |
12 |
Correct |
7 ms |
588 KB |
Output is correct |
13 |
Correct |
7 ms |
584 KB |
Output is correct |
14 |
Correct |
98 ms |
676 KB |
Output is correct |
15 |
Correct |
85 ms |
664 KB |
Output is correct |
16 |
Correct |
113 ms |
584 KB |
Output is correct |
17 |
Correct |
110 ms |
588 KB |
Output is correct |
18 |
Correct |
104 ms |
672 KB |
Output is correct |
19 |
Correct |
77 ms |
664 KB |
Output is correct |
20 |
Correct |
16 ms |
588 KB |
Output is correct |
21 |
Correct |
16 ms |
688 KB |
Output is correct |
22 |
Correct |
16 ms |
584 KB |
Output is correct |
23 |
Correct |
19 ms |
688 KB |
Output is correct |
24 |
Correct |
1 ms |
588 KB |
Output is correct |
25 |
Correct |
78 ms |
680 KB |
Output is correct |
26 |
Correct |
91 ms |
680 KB |
Output is correct |
27 |
Correct |
61 ms |
588 KB |
Output is correct |
28 |
Correct |
87 ms |
708 KB |
Output is correct |
29 |
Correct |
95 ms |
668 KB |
Output is correct |
30 |
Correct |
109 ms |
676 KB |
Output is correct |