#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>
#define int ll
using namespace std;
const int N = 1e5 + 5,inf = 1e18;
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 |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2904 KB |
Output is correct |
10 |
Correct |
2 ms |
2560 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2396 KB |
Output is correct |
2 |
Correct |
25 ms |
2816 KB |
Output is correct |
3 |
Correct |
37 ms |
4700 KB |
Output is correct |
4 |
Correct |
276 ms |
6600 KB |
Output is correct |
5 |
Correct |
51 ms |
4696 KB |
Output is correct |
6 |
Correct |
16 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2908 KB |
Output is correct |
2 |
Correct |
5 ms |
2908 KB |
Output is correct |
3 |
Correct |
4 ms |
2904 KB |
Output is correct |
4 |
Correct |
5 ms |
2904 KB |
Output is correct |
5 |
Correct |
1 ms |
2804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2904 KB |
Output is correct |
10 |
Correct |
2 ms |
2560 KB |
Output is correct |
11 |
Correct |
2 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
22 ms |
2396 KB |
Output is correct |
15 |
Correct |
25 ms |
2816 KB |
Output is correct |
16 |
Correct |
37 ms |
4700 KB |
Output is correct |
17 |
Correct |
276 ms |
6600 KB |
Output is correct |
18 |
Correct |
51 ms |
4696 KB |
Output is correct |
19 |
Correct |
16 ms |
2396 KB |
Output is correct |
20 |
Correct |
6 ms |
2908 KB |
Output is correct |
21 |
Correct |
5 ms |
2908 KB |
Output is correct |
22 |
Correct |
4 ms |
2904 KB |
Output is correct |
23 |
Correct |
5 ms |
2904 KB |
Output is correct |
24 |
Correct |
1 ms |
2804 KB |
Output is correct |
25 |
Correct |
94 ms |
4944 KB |
Output is correct |
26 |
Correct |
135 ms |
10064 KB |
Output is correct |
27 |
Correct |
57 ms |
14052 KB |
Output is correct |
28 |
Correct |
179 ms |
17596 KB |
Output is correct |
29 |
Correct |
182 ms |
24968 KB |
Output is correct |
30 |
Correct |
128 ms |
8496 KB |
Output is correct |