This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MaxN = 3e2 + 5;
int n, m, k;
int a[MaxN];
int b[MaxN];
void Inp()
{
cin >> n >> m >> k;
for (int x = 1; x <= n; x++)
{
cin >> a[x];
}
for (int x = 1; x <= m; x++)
{
cin >> b[x];
}
}
int F[MaxN][MaxN * MaxN + 5];
void Exc()
{
int suma = 0, sumb = 0;
for (int x = 1; x <= n; x++)
{
suma += a[x];
if (a[x] < k || m < k)
{
cout << "Impossible";
return;
}
}
for (int x = 1; x <= m; x++)
{
sumb += b[x];
}
for (int x = 0; x <= m; x++)
{
for (int y = 0; y <= sumb; y++)
{
F[x][y] = -1;
}
}
for (int x = 1; x <= m; x++)
{
for (int y = 0; y < b[x]; y++)
{
if (F[x - 1][y] != -1)
{
F[x][y] = F[x - 1][y];
}
}
for (int y = b[x]; y <= sumb; y++)
{
if (F[x - 1][y] != -1)
{
F[x][y] = F[x - 1][y];
}
if (F[x - 1][y - b[x]] != -1)
{
F[x][y] = max(F[x][y], F[x - 1][y - b[x]] + min(b[x], n));
}
}
}
for (int x = suma; x <= sumb; x++)
{
if (F[m][x] >= n * k)
{
cout << x - suma;
return;
}
}
cout << "Impossible";
}
int main()
{
//freopen("F.INP", "r", stdin);
//freopen("F.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test = 1;
//cin >> test;
for (int x = 1; x <= test; x++)
{
Inp();
Exc();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |