#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e5 + 5;
const int INF = 1e9 + 7;
signed main(void){
fastio;
int n, m, k;
cin>>n>>m>>k;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++) cin>>a[i];
for(int i = 0; i < m; i++) cin>>b[i];
for(int i = 0; i < n; i++){
if(a[i] < k){
cout<<"Impossible\n";
return 0;
}
}
vector<int> dp(maxn, -INF);
dp[0] = 0;
for(int i = 0; i < m; i++){
for(int j = maxn - 1; j >= b[i]; j--){
dp[j] = max(dp[j], dp[j - b[i]] + min(n, b[i]));
}
}
int ttl = accumulate(a.begin(), a.end(), 0);
for(int i = ttl; i < maxn; i++){
if(dp[i] >= n * k){
cout<<i - ttl<<"\n";
return 0;
}
}
cout<<"Impossible\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1220 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1220 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1116 KB |
Output is correct |
2 |
Correct |
19 ms |
1116 KB |
Output is correct |
3 |
Correct |
30 ms |
1116 KB |
Output is correct |
4 |
Correct |
27 ms |
1112 KB |
Output is correct |
5 |
Correct |
30 ms |
1116 KB |
Output is correct |
6 |
Correct |
19 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1116 KB |
Output is correct |
2 |
Correct |
4 ms |
1116 KB |
Output is correct |
3 |
Correct |
4 ms |
1116 KB |
Output is correct |
4 |
Correct |
5 ms |
1116 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1220 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
1116 KB |
Output is correct |
11 |
Correct |
2 ms |
1116 KB |
Output is correct |
12 |
Correct |
2 ms |
1116 KB |
Output is correct |
13 |
Correct |
2 ms |
1116 KB |
Output is correct |
14 |
Correct |
23 ms |
1116 KB |
Output is correct |
15 |
Correct |
19 ms |
1116 KB |
Output is correct |
16 |
Correct |
30 ms |
1116 KB |
Output is correct |
17 |
Correct |
27 ms |
1112 KB |
Output is correct |
18 |
Correct |
30 ms |
1116 KB |
Output is correct |
19 |
Correct |
19 ms |
1116 KB |
Output is correct |
20 |
Correct |
4 ms |
1116 KB |
Output is correct |
21 |
Correct |
4 ms |
1116 KB |
Output is correct |
22 |
Correct |
4 ms |
1116 KB |
Output is correct |
23 |
Correct |
5 ms |
1116 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
18 ms |
1116 KB |
Output is correct |
26 |
Correct |
21 ms |
1112 KB |
Output is correct |
27 |
Correct |
19 ms |
1116 KB |
Output is correct |
28 |
Correct |
24 ms |
1116 KB |
Output is correct |
29 |
Correct |
28 ms |
1116 KB |
Output is correct |
30 |
Correct |
30 ms |
1116 KB |
Output is correct |