#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define ar array
#define ld long double
#define int long long
#define all(v) v.begin(), v.end()
const int N = 5e4 + 20;
const int K = 469;
const int LOG = 26;
const int INF = 1e9;
int MOD = 998244353;
void chmin(int &x,int y){x = min(x, y);}
void chmax(int &x,int y){x = max(x, y);}
int n, k, m, q;
struct Koce{
vector<vector<int> > A;
Koce(){
A.resize(k, vector<int>(k, INF));
}
};
Koce operator+(Koce a, Koce b){
Koce ans;
for(int i = 0;i < k;i++){
for(int j = 0;j < k;j++){
for(int x = 0;x < k;x++)chmin(ans.A[i][j], a.A[i][x] + b.A[x][j]);
}
}
return ans;
}
Koce s[4 * N];
void bld(int u,int tl,int tr, Koce A[]){
if(tl == tr){
s[u] = A[tl];
return;
}
int tm = (tl + tr) / 2;
bld(u * 2, tl, tm, A);
bld(u * 2 + 1, tm + 1, tr, A);
s[u] = s[u * 2] + s[u * 2 + 1];
}
Koce qry(int u,int tl,int tr,int l,int r){
if(l > tr || tl > r){
Koce ret;
for(int i = 0;i < k;i++)ret.A[i][i] = 0;
return ret;
}
if(l <= tl && tr <= r)return s[u];
int tm = (tl + tr) / 2;
return qry(u * 2, tl, tm, l, r) + qry(u * 2 + 1,tm + 1, tr, l, r);
}
void orz(){
int n, m, k;
cin>>n>>m>>k;
int A[n], B[m];
int s1 = 0,s2 = 0;
for(int i = 0;i < n;i++){
cin>>A[i];
if(A[i] < k){
cout<<"Impossible";
return;
}
s1 += A[i];
}
for(int i = 0;i < m;i++){
cin>>B[i];
s2 += B[i];
}
int dp[m + 1][s2 + 1];
memset(dp, -0x3f, sizeof dp);
dp[0][0] = 0;
for(int i = 0;i < m;i++){
for(int j = 0;j <= s2;j++){
chmax(dp[i + 1][j], dp[i][j]);
if(j + B[i] <= s2)chmax(dp[i + 1][j + B[i]], dp[i][j] + min(n, B[i]));
}
}
for(int i = s1;i <= s2;i++){
if(dp[m][i] >= n * k){
cout<<i - s1;
return;
}
}
cout<<"Impossible";
}
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
int t;
//cin>>t;
t = 1;
while(t--)orz();
}
# | 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... |