#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 303;
const int mxc = mxn*mxn;
int N,M,K,arr[mxn],dp[mxc],brr[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>K;
int sum = 0;
for(int i = 0;i<N;i++)cin>>arr[i],sum += arr[i];
for(int i = 0;i<M;i++)cin>>brr[i];
for(int i = 0;i<N;i++){
if(arr[i]<K){
cout<<"Impossible";
return 0;
}
}
memset(dp,-1,sizeof(dp));
dp[0] = 0;
for(int i = 0;i<M;i++){
for(int j = mxc-1;j>=brr[i];j--){
if(dp[j-brr[i]] != -1)dp[j] = max(dp[j],dp[j-brr[i]]+min(brr[i],N));
}
}
for(int i = sum;i<mxc;i++){
if(dp[i]>=N*K){
cout<<i-sum;
return 0;
}
}
cout<<"Impossible";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
1 ms |
696 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
1 ms |
696 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
824 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
816 KB |
Output is correct |
2 |
Correct |
15 ms |
604 KB |
Output is correct |
3 |
Correct |
20 ms |
604 KB |
Output is correct |
4 |
Correct |
22 ms |
604 KB |
Output is correct |
5 |
Correct |
24 ms |
820 KB |
Output is correct |
6 |
Correct |
18 ms |
816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
604 KB |
Output is correct |
2 |
Correct |
6 ms |
604 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
1 ms |
696 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
824 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
19 ms |
816 KB |
Output is correct |
15 |
Correct |
15 ms |
604 KB |
Output is correct |
16 |
Correct |
20 ms |
604 KB |
Output is correct |
17 |
Correct |
22 ms |
604 KB |
Output is correct |
18 |
Correct |
24 ms |
820 KB |
Output is correct |
19 |
Correct |
18 ms |
816 KB |
Output is correct |
20 |
Correct |
5 ms |
604 KB |
Output is correct |
21 |
Correct |
6 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
25 ms |
604 KB |
Output is correct |
26 |
Correct |
20 ms |
824 KB |
Output is correct |
27 |
Correct |
20 ms |
604 KB |
Output is correct |
28 |
Correct |
30 ms |
600 KB |
Output is correct |
29 |
Correct |
20 ms |
604 KB |
Output is correct |
30 |
Correct |
29 ms |
604 KB |
Output is correct |