This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define N 90001
int dp[N];
void solve(){
int n,m,o,p,q,r;
cin>>n>>m>>o;
for(int i=0;i<N;i++)
dp[i]=-1e8;
for(int i=dp[0]=r=0;i<n;i++){
cin>>p;
r+=p;
if(p<o){
cout<<"Impossible";
return;
}
}
for(int i=0;i<m;i++){
cin>>p;
q=min(p,n);
for(int j=N-p-1;j>=0;j--)
dp[j+p]=max(dp[j+p],dp[j]+q);
}
for(int i=0;r+i<N;i++){
if(dp[i+r]>=o){
cout<<i;
return;
}
}
cout<<"Impossible";
}
int main(){
L0TA;
solve();
return 0;
}
# | 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... |