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 pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
using namespace std;
const int inf = 1e9;
void p(auto A){
for(auto e : A)cout << e << ' ';
cout << '\n';
}
void solve(){
int n, m, k; cin >> n >> m >> k;
vector<int>A(n), B(m);
for(int i = 0; i< n; i++)cin >> A[i];
for(int i = 0; i< m; i++)cin >> B[i];
for(auto e : A)if(e < k){
cout << "Impossible";
return;
}
int tot = accumulate(all(B), 0);
vector<int> dp(tot+5, -inf);
dp[0] = 0;
auto xmax = [](int& a, int b){a=max(a, b);};
for(int i = 0; i< m; i++){
for(int j = tot-B[i]; j >= 0; j--){
xmax(dp[j+B[i]], dp[j]+min(n, B[i]));
}
}
int sma = accumulate(all(A), 0);
for(int i = sma; i<= tot; i++){
if(dp[i] >= k*n){
cout << i-sma;
return;
}
}
cout << "Impossible";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while(t--)solve();
}
Compilation message (stderr)
kitchen.cpp:15:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
15 | void p(auto A){
| ^~~~
# | 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... |