#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3NRqilq ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
void chmin(int&a,int b){
a=min(a,b);
}
signed main(){
_3NRqilq;
int n,m,k;
cin>>n>>m>>k;
vi a(n);
rep(i,n){
cin>>a[i];
}
vi b(m);
rep(i,m){
cin>>b[i];
}
if(k>m){
cout<<"Impossible\n";
return 0;
}
const int _n=10001;
const int inf=1e9;
vec(vi) dp(_n+1,vi(m+1,inf)),ndp;
// minimum additional, k
dp[0][0]=0;
rep(i,m){
int v=b[i];
// if(v<n) continue;
ndp=dp;
for(int j=0;j<=_n-v;j++){
rep(e,m){
int nj=j+v;
int ne=e+1;
chmin(ndp[nj][ne],dp[j][e]);
}
}
rep(e,m+1){
for(int j=_n-1;j>=e;j--){
chmin(ndp[j][e],ndp[j+1][e]+1);
}
}
dp.swap(ndp);
}
int sun=0;
rep(i,n){
sun+=a[i];
if(a[i]<k){
cout<<"Impossible\n";
return 0;
}
}
int ans=inf;
rng(i,k,m+1)chmin(ans,dp[sun][i]);
if(ans>=inf){
cout<<"Impossible\n";
}else{
cout<<ans<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1364 KB |
Output is correct |
4 |
Correct |
2 ms |
1364 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1364 KB |
Output is correct |
4 |
Correct |
2 ms |
1364 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
1364 KB |
Output is correct |
9 |
Correct |
15 ms |
3516 KB |
Output is correct |
10 |
Correct |
14 ms |
3620 KB |
Output is correct |
11 |
Incorrect |
15 ms |
3624 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1071 ms |
42020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
106 ms |
7352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1364 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1364 KB |
Output is correct |
4 |
Correct |
2 ms |
1364 KB |
Output is correct |
5 |
Correct |
2 ms |
1364 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1364 KB |
Output is correct |
8 |
Correct |
2 ms |
1364 KB |
Output is correct |
9 |
Correct |
15 ms |
3516 KB |
Output is correct |
10 |
Correct |
14 ms |
3620 KB |
Output is correct |
11 |
Incorrect |
15 ms |
3624 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |