#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");
vector<int> v[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;
}
sort(b, b + n);
for(int i = m - 1; i >= 0; i--) {
for(int j = sum; j >= b[i]; j--) {
if(j == b[i] || v[j - b[i]].size()) {
if(v[j - b[i]].size() + 1 > v[j].size()) {
v[j] = v[j - b[i]];
v[j].push_back(b[i]);
}
}
}
}
for(int i = x; i <= sum; i++) {
if(v[i].size() >= k) {
int y = 0, z = 0;
for(int o : v[i]) {
y += o;
z += min(n, o);
}
if(y >= x && z >= n * k) {
cout << y - x;
return 0;
}
}
}
cout << "Impossible";
return 0;
}
Compilation message
kitchen.cpp: In function 'int main()':
kitchen.cpp:55:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if(v[i].size() >= k) {
| ~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
21556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2388 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |