Submission #725981

#TimeUsernameProblemLanguageResultExecution timeMemory
725981fdnfksdKitchen (BOI19_kitchen)C++14
100 / 100
119 ms1824 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...