이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const ll maxn = 302, LG = 21, mod = 998244353, inf = 1e18;
ll n, m, k, a[maxn], b[maxn], req = 0, tot = 0, dp[maxn][maxn*maxn];
int main ()
{
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
req += a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> b[i];
tot += b[i];
}
if (m < k || tot < req)
{
cout << "Impossible";
return 0;
}
for (int i = 1; i <= n; i++)
if (a[i] < k)
{
cout << "Impossible";
return 0;
}
for (int i = 0; i <= m; i++)
for (int j = 0; j <= tot; j++) dp[i][j] = -1;
dp[0][0] = 0;
for (int i = 0; i < m; i++)
for (int j = 0; j <= tot; j++)
{
if (dp[i][j] == -1) continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (j + b[i + 1] <= tot) dp[i + 1][j + b[i + 1]] = max(dp[i + 1][j + b[i + 1]], dp[i][j] + min(b[i + 1], n));
}
for (int i = req; i <= tot; i++)
if (dp[m][i] >= n*k)
{
cout << i - req;
return 0;
}
cout << "Impossible";
}
# | 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... |