#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<int,pii> ipii;
typedef pair<pii,pii> ipiii;
const int MAXN = 310;
const int SQRT = 610;
const int MAXA = 9e4+30;
const int MOD = 1e6+7;
const int INF = 2e9+10;
const int LOG = 19;
const ld EPS = 1e-12;
void chmx(int &a, int b){ a = max(a,b); }
void chmn(int &a, int b){ a = min(a,b); }
int n, m, k;
int a[MAXN], b[MAXN];
bool dp[MAXA];
bool can = 1;
int mn = INF;
signed main(){
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m >> k;
int tot = 0;
for(int i=1; i<=n; i++){
cin >> a[i]; tot += a[i];
if(a[i] < k) can = 0;
}
if(m < k) can = 0;
for(int i=1; i<=m; i++) cin >> b[i];
if(!can){
cout << "Impossible\n"; return 0;
}
for(int p=0; p<(1<<m); p++){
int nw = 0, sum = 0; bool bisa = 1;
for(int i=0; i<m; i++){
if((p>>i)&1){
nw += b[i+1];
sum += min(b[i+1], n);
}
}
if(nw < tot || sum<n*k) continue;
// for(int i=1; i<=n; i++){
// // cout << i << " i\n";
// vector <int> vec;
// for(int j=1; j<=k; j++){
// if(pq.empty()){
// bisa = 0; break;
// }
// int tp = pq.top(); pq.pop();
// // cout << tp << ' ';
// if(tp-1 >= 1) vec.pb(tp-1);
// }
// // cout << " tp\n";
// if(!bisa) break;
// for(auto in : vec) pq.push(in);
// }
// cout << nw << ' ' <<bisa <<' '<< p << " p\n";
if(bisa)
mn = min(mn, nw);
}
if(mn==INF) cout << "Impossible\n";
else cout << mn-tot << '\n';
}
# | 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... |