///~~~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
#define M 89701
bitset<M> dp[N];
void solve(){
int n,m,o,p,q,r;
bitset<M> tmp;
cin>>n>>m>>o;
dp[0][0]=1;
r=0;
for(int i=0;i<n;i++){
cin>>p;
r+=p;
if(p<o){
cout<<"Impossible";
return;
}
}
r-=n*o;
for(int i=0;i<m;i++){
cin>>p;
q=max(0,p-n);
p-=q;
for(int j=n*o;j>=0;j--){
tmp=dp[j];
tmp<<=(q+max(0,p+j-n*o));
dp[min(j+p,n*o)]|=tmp;
}
}
for(int i=0;r+i<N;i++){
if(dp[n*o][r+i]){
cout<<i;
return;
}
}
cout<<"Impossible";
}
int main(){
L0TA;
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
2648 KB |
Output is correct |
12 |
Correct |
4 ms |
1880 KB |
Output is correct |
13 |
Correct |
64 ms |
21080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
960 KB |
Output is correct |
2 |
Correct |
118 ms |
1096 KB |
Output is correct |
3 |
Correct |
118 ms |
3420 KB |
Output is correct |
4 |
Correct |
145 ms |
748 KB |
Output is correct |
5 |
Correct |
159 ms |
576 KB |
Output is correct |
6 |
Correct |
110 ms |
3708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
8996 KB |
Output is correct |
2 |
Correct |
40 ms |
7820 KB |
Output is correct |
3 |
Correct |
34 ms |
7772 KB |
Output is correct |
4 |
Correct |
83 ms |
16220 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
2648 KB |
Output is correct |
12 |
Correct |
4 ms |
1880 KB |
Output is correct |
13 |
Correct |
64 ms |
21080 KB |
Output is correct |
14 |
Correct |
133 ms |
960 KB |
Output is correct |
15 |
Correct |
118 ms |
1096 KB |
Output is correct |
16 |
Correct |
118 ms |
3420 KB |
Output is correct |
17 |
Correct |
145 ms |
748 KB |
Output is correct |
18 |
Correct |
159 ms |
576 KB |
Output is correct |
19 |
Correct |
110 ms |
3708 KB |
Output is correct |
20 |
Correct |
60 ms |
8996 KB |
Output is correct |
21 |
Correct |
40 ms |
7820 KB |
Output is correct |
22 |
Correct |
34 ms |
7772 KB |
Output is correct |
23 |
Correct |
83 ms |
16220 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Runtime error |
197 ms |
262144 KB |
Execution killed with signal 9 |
26 |
Halted |
0 ms |
0 KB |
- |