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
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 300 + 9;
const ll inf = 1e9 + 7;
ll n,m,k,a[N],dp[N][N*N],b[N],ans = inf,sum;
void endgame(){
cout<<"Impossible"; exit(0);
}
ll f(ll pos,ll total){
if (!pos && total) return -inf;
if (!total || !pos) return 0;
ll &res = dp[pos][total];
if (res != -1) return res;
res = f(pos - 1,total);
if (total >= b[pos]) res = max(res,f(pos - 1,total - b[pos]) + min(b[pos],n));
return res;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>m>>k;
for (ll i = 1;i <= n;i++) cin>>a[i],sum += a[i];
for (ll i = 1;i <= m;i++) cin>>b[i];
if (*min_element(a + 1,a + n + 1) < k) endgame();
memset(dp,-1,sizeof(dp)); //debug(f(m,sum));
for (ll i = sum;i < N*N;i++)
if (f(m,i) >= n*k) ans = min(ans,i);
if (ans == inf) endgame();
debug(ans - sum);
}
/// be confident
Compilation message (stderr)
kitchen.cpp: In function 'int main()':
kitchen.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |