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 TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=300*300+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll dp[2][maxN];
ll n,m,a[maxN],b[maxN];
ll k,sum=0;
void solve()
{
cin >> n >> m >> k;
for(int i=1;i<=n;i++) cin >> a[i],sum+=a[i];
for(int i=1;i<=m;i++) cin >> b[i];
dp[0][0]=0;
for(int i=1;i<=n;i++) if(a[i]<k) {cout << "Impossible";return;}
for(int i=1;i<maxN;i++) dp[0][i]=-inf;
for(int i=1;i<=m;i++)
{
for(int j=b[i];j<maxN;j++)
{
ll cc=min(b[i],n);
dp[i&1][j]=max(dp[(i-1)&1][j],dp[(i-1)&1][j-b[i]]+cc);
}
for(int j=0;j<b[i];j++)
{
dp[i&1][j]=dp[(i-1)&1][j];
}
}
for(int i=sum;i<maxN;i++)
{
if(dp[m&1][i]>=n*k)
{
cout << i-sum;
return;
}
}
{cout << "Impossible";return;}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# | 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... |