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>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int dp[305*305];
void solve(){
int n,m,k;
cin >> n >> m >> k;
int arr[n];
int counter=0;
bool amos=true;
for(int x=0;x<n;x++){
cin >> arr[x];
counter+=arr[x];
if(arr[x]<k) amos=false;
}
int chef[m];
for(int x=0;x<m;x++){
cin >> chef[x];
}
for(int x=0;x<m;x++){
for(int take=305*305-1;take>=0;take--){
int nxt=take+chef[x];
int add=dp[take]+min(chef[x],n);
if(nxt<305*305){
dp[nxt]=max(dp[nxt],add);
}
}
}
int ans=1e15;
for(int x=0;x<305*305;x++){
//if(x<15) cout << dp[x] << " ";
if(x>=counter&&dp[x]>=n*k){
ans=min(ans,x-counter);
}
}
if(ans>1e9||!amos){
cout << "Impossible\n";
}
else cout << ans;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |