#include <iostream>
#include <fstream>
#include <bitset>
#include <algorithm>
using namespace std;
const int nmax=305;
bitset<nmax*nmax> pot,dp[nmax];
int minim[nmax*nmax];
int a[nmax];
int n,m,k,sum,i,j,x;
int main()
{
//freopen("data.in","r",stdin);
ios_base::sync_with_stdio(false);
cin>>n>>m>>k;
for(i=1;i<=n;i++)
{
cin>>x;sum+=x;
if(x<k)
{
cout<<"Impossible\n";
return 0;
}
}
for(i=1;i<=m;i++)
cin>>a[i];
sort(a+1,a+m+1);
pot[0]=1;
for(i=1;i<=m&&a[i]<=n;i++)
{
pot=(pot|(pot<<a[i]));
}
dp[0][0]=1;
for(i=m;i>=1&&a[i]>n;i--)
{
for(j=m-1;j>=0;j--)
dp[j+1]=(dp[j+1]|(dp[j]<<a[i]));
}
minim[90001]=(1<<30);
for(i=90000;i>=0;i--)
{
if(pot[i]==1) minim[i]=i;
else minim[i]=minim[i+1];
}
int ans=(1<<30);
for(i=0;i<=m;i++)
for(j=0;j<=90000;j++)
if(dp[i][j]==1)
ans=min(ans,j+minim[max(max((k-i)*n,sum-j),0)]);
if(ans==(1<<30)) cout<<"Impossible\n";
else cout<<ans-sum;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
3 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
3 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
6 ms |
888 KB |
Output is correct |
10 |
Correct |
6 ms |
1016 KB |
Output is correct |
11 |
Correct |
6 ms |
888 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
760 KB |
Output is correct |
2 |
Correct |
32 ms |
760 KB |
Output is correct |
3 |
Correct |
57 ms |
4216 KB |
Output is correct |
4 |
Correct |
241 ms |
4156 KB |
Output is correct |
5 |
Correct |
40 ms |
888 KB |
Output is correct |
6 |
Correct |
30 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1144 KB |
Output is correct |
2 |
Correct |
13 ms |
1144 KB |
Output is correct |
3 |
Correct |
8 ms |
760 KB |
Output is correct |
4 |
Correct |
8 ms |
760 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
760 KB |
Output is correct |
3 |
Correct |
3 ms |
760 KB |
Output is correct |
4 |
Correct |
3 ms |
760 KB |
Output is correct |
5 |
Correct |
3 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
760 KB |
Output is correct |
9 |
Correct |
6 ms |
888 KB |
Output is correct |
10 |
Correct |
6 ms |
1016 KB |
Output is correct |
11 |
Correct |
6 ms |
888 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
812 KB |
Output is correct |
14 |
Correct |
36 ms |
760 KB |
Output is correct |
15 |
Correct |
32 ms |
760 KB |
Output is correct |
16 |
Correct |
57 ms |
4216 KB |
Output is correct |
17 |
Correct |
241 ms |
4156 KB |
Output is correct |
18 |
Correct |
40 ms |
888 KB |
Output is correct |
19 |
Correct |
30 ms |
760 KB |
Output is correct |
20 |
Correct |
17 ms |
1144 KB |
Output is correct |
21 |
Correct |
13 ms |
1144 KB |
Output is correct |
22 |
Correct |
8 ms |
760 KB |
Output is correct |
23 |
Correct |
8 ms |
760 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
285 ms |
3232 KB |
Output is correct |
26 |
Correct |
291 ms |
3448 KB |
Output is correct |
27 |
Correct |
117 ms |
2520 KB |
Output is correct |
28 |
Correct |
231 ms |
3548 KB |
Output is correct |
29 |
Correct |
414 ms |
3548 KB |
Output is correct |
30 |
Correct |
297 ms |
4216 KB |
Output is correct |