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>
#define ll int
using namespace std;
#define bit(x,y) ((x >> y) & 1)
const ll mod = 1e9 + 7;
const ll inf = INT_MIN/2;
ll d[305][305 * 305];
ll a[305],b[305];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,m,k;
cin >> n >> m >> k;
ll i,j;
ll s = 0;
for(i = 1;i <= n;i++)
{
cin >> a[i];
s += a[i];
}
for(i = 1;i <= m;i++) cin >> b[i];
for(i = 0;i <= 300;i++)
{
for(j = 0;j <= 300 * 300;j++)
{
d[i][j] = inf;
}
}
d[0][0] = 0;
for(i = 1;i <= m;i++)
{
for(j = 0;j <= 300 * 300;j++)
{
if(d[i - 1][j] == inf) continue;
d[i][j] = max(d[i][j],d[i - 1][j]);
if(j + b[i] <= 300 * 300) d[i][j + b[i]] = max(d[i][j + b[i]],d[i - 1][j] + min(b[i],n));
}
}
ll ans = -1;
for(i = s;i <= 300 * 300;i++)
{
if(d[m][i] >= n * k)
{
ans = i - s;
break;
}
}
if(ans == -1) cout << "Impossible";
else cout << ans;
}
# | 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... |