This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Code by Parsa Eslami
#include <bits/stdc++.h>
//#define int long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cerr<<#x<<" : "<<x<<'\n'
#define IMP "Impossible\n"
using namespace std;
const int N=300+3;
int n,m,k;
int F[N];
int C[N];
int S;
bitset<N*N> btl;
bitset<N*N> bth[N];
const int INF=1e7;
int sum;
int ps[N*N];
int bs(int h,int x){
int l=max(x-1,-1); int r=N*N;
if(ps[N*N-1]-ps[l]==0) return INF;
while(r-l>1){
int mid=(r+l)/2;
if(ps[mid]-ps[l]!=0) r=mid;
else l=mid;
}
return r;
}
void pre(){
btl[0]=1;
FOR(i,1,m) if(C[i]<n){
btl=btl|(btl<<C[i]);
}
bth[0][0]=1;
FOR(i,1,m) if(C[i]>=n){
FORR(h,i,1) bth[h]=bth[h]|(bth[h-1]<<C[i]);
}
}
void solve(){
FOR(t,0,m){
ps[0]=bth[t][0];
FOR(i,1,N*N-1) ps[i]=ps[i-1]+bth[t][i];
int st=k*n-t*n;
FOR(j,max(0,st),N*N-1)
if(btl[j]){
sum=min(sum,j+bs(t,S-j));
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
bool ex=0;
cin>>n>>m>>k;
FOR(i,1,n){
cin>>F[i];
S+=F[i];
if(F[i]<k){
ex=1;
}
}
int x0=0;
FOR(i,1,m){
cin>>C[i];
sum+=C[i];
x0+=min(C[i],n);
}
if(sum<S||x0<k*n||ex){
cout<<IMP;
exit(0);
}
pre();
solve();
cout<<sum-S<<'\n';
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... |