#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define left (h*2),l,(l + r)/2
#define right (h*2+1),(l+r)/2 + 1,r
#define pii pair <int,int>
using namespace std;
const int N = 1e5 + 5,inf = 1e9;
int a[N],b[N],sA;
bitset <90001> dp2[305];
set <int> st[303];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m,k;
cin>>n>>m>>k;
for (int i = 1; i <= n; i++){
cin >> a[i];
sA += a[i];
if (a[i] < k) {
cout<<"Impossible";
exit(0);
}
}
for (int i = 1; i <= m; i++)
cin >> b[i];
bitset <90001> dp;
dp[0] = 1;
for (int i = 1; i <= m; i++){
if (b[i] >= n) continue;
dp |= (dp << b[i]);
}
dp2[0][0] = 1;
for (int i = 1; i <= m; i++){
if (b[i] < n) continue;
for (int x = m; x >= 1; x--){
dp2[x] |= (dp2[x - 1] << b[i]);
}
}
for (int x=0;x<=m;x++)
for (int s=0;s<=90000;s++)
if (dp2[x][s]) st[x].insert(s);
int ans = inf;
for (int s1 = 0; s1 <= 90000; s1++){
if (!dp[s1]) continue;
for (int x = 0; x <= m; x++){
if (s1 + x*n < k*n) continue;
set <int> :: iterator it = st[x].lower_bound(sA - s1);
if (it != st[x].end()){
ans = min(ans,s1 + (*it) - sA);
}
}
}
if (ans == inf){
cout<<"Impossible";
}else{
cout<<ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
348 KB |
Output is correct |
2 |
Correct |
18 ms |
348 KB |
Output is correct |
3 |
Correct |
32 ms |
3676 KB |
Output is correct |
4 |
Correct |
266 ms |
5716 KB |
Output is correct |
5 |
Correct |
50 ms |
3672 KB |
Output is correct |
6 |
Correct |
15 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
856 KB |
Output is correct |
2 |
Correct |
5 ms |
860 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
22 ms |
348 KB |
Output is correct |
15 |
Correct |
18 ms |
348 KB |
Output is correct |
16 |
Correct |
32 ms |
3676 KB |
Output is correct |
17 |
Correct |
266 ms |
5716 KB |
Output is correct |
18 |
Correct |
50 ms |
3672 KB |
Output is correct |
19 |
Correct |
15 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
856 KB |
Output is correct |
21 |
Correct |
5 ms |
860 KB |
Output is correct |
22 |
Correct |
3 ms |
860 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
96 ms |
3084 KB |
Output is correct |
26 |
Correct |
136 ms |
8556 KB |
Output is correct |
27 |
Correct |
61 ms |
12124 KB |
Output is correct |
28 |
Correct |
203 ms |
15824 KB |
Output is correct |
29 |
Correct |
174 ms |
23224 KB |
Output is correct |
30 |
Correct |
123 ms |
7504 KB |
Output is correct |