#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
int dp[90001];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
int a[n], b[m];
int x = 0;
bool bad = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
if(a[i] < k)
bad = 1;
}
int sum = 0;
for(int i = 0; i < m; i++) {
cin >> b[i];
sum += b[i];
}
if(bad) {
cout << "Impossible";
return 0;
}
if(k == 1) {
dp[0] = 1;
for(int i = 0; i < m; i++) {
for(int j = 90000; j >= b[i]; j--)
dp[j] |= dp[j - b[i]];
}
for(int i = x; i <= 90000; i++) {
if(dp[i]) {
cout << i - x;
return 0;
}
}
cout << "Impossible";
return 0;
}
sort(b, b + n);
for(int i = m - 1; i >= 0; i--) {
for(int j = sum; j >= b[i]; j--) {
if(dp[j - b[i]] + min(n, b[i]) > dp[j])
dp[j] = dp[j - b[i]] + min(n, b[i]);
}
}
for(int i = x; i <= sum; i++) {
if(dp[i] >= n * k) {
cout << i - x;
return 0;
}
}
cout << "Impossible";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
684 KB |
Output is correct |
2 |
Correct |
10 ms |
684 KB |
Output is correct |
3 |
Correct |
13 ms |
684 KB |
Output is correct |
4 |
Correct |
16 ms |
596 KB |
Output is correct |
5 |
Correct |
15 ms |
596 KB |
Output is correct |
6 |
Correct |
11 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |