#include <bits/stdc++.h>
using namespace std;
int a[305], b[305];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k, x1=0, x2=0;
cin >> n >> m >> k;
for (int i=1; i<=n; i++)
{
cin >> a[i];
x1+=a[i];
}
for (int i=1; i<=m; i++)
{
cin >> b[i];
x2+=b[i];
}
if (m<k || x1>x2)
{
cout << "Impossible";
return 0;
}
sort(b+1, b+m+1);
for (int i=1; i<=n; i++)
{
if (a[i]<k)
{
cout << "Impossible";
return 0;
}
for (int j=m-k+1; j<=m; j++)
{
b[j]--;
if (b[j]<0)
{
cout << "Impossible";
return 0;
}
}
sort(b+1, b+m+1);
int l=0, r=300;
while (l<r)
{
int mid=(l+r)/2, sum=0;
for (int j=1; j<=m; j++)
{
if (b[j]<mid)
break;
sum+=b[j]-mid;
}
if (sum<=a[i]-k)
r=mid;
else
l=mid+1;
}
int sum=0;
for (int j=m; j>=1; j--)
{
if (b[j]<l)
break;
sum+=b[j]-l;
}
sort(b+1, b+m+1);
for (int j=m; j>=m-(a[j]-k-sum)+1; j--)
b[j]--;
sort(b+1, b+m+1);
}
cout << x2-x1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |