#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int mod = 1e17;
const int N = 300;
int can[300 * 300 + 10];
int goal(vector<int> &srt, int k){
int cnt = 0;
while(true){
sort(srt.rbegin(), srt.rend());
if(srt[k-1] <= 0){
break;
}
int mn = srt[k-1];
for(int i = 0;i < k; i++){
srt[i]-= mn;
}
cnt+= mn;
}
return cnt;
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k;
vector<int> a, b;
cin >> n >> m >> k;
a.resize(n);
for(auto &e : a) cin >> e;
b.resize(m);
for(auto &e : b) cin >> e;
int ans = mod;
if(k > m or *min_element(all(a)) < k){
cout << "Impossible";
return 0;
}
int sumX = accumulate(all(a), 0LL);
if(sumX > accumulate(all(b), 0LL)){
cout << "Impossible";
return 0;
}
can[0] = 0;
for(int i = N*N; i >= 0; i--) can[i] = INT_MIN;
for(int x : b){
for(int i = N*N; i - x >= 0; i--){
can[i] = max(can[i], can[i-x] + min(x, n));
}
}
for(int i = sumX; i <= N*N; i++){
if(can[i] >= n * k){
cout << i-sumX;
return 0;
}
}
// if(k == 1 && m > 15){
// can[0] = 1;
// for(int x : b){
// for(int i = N*N; i - x >= 0; i--){
// can[i]|= can[i-x];
// }
// }
// int sumX = accumulate(all(a), 0LL);
// if(goal(b, k) < n){
// cout << "Impossible";
// return 0;
// }
// for(int i = sumX; i <= N*N; i++){
// if(can[i]){
// cout << i-sumX;
// return 0;
// }
// }
// cout << "Impossible";
// return 0;
// }
cout << "Impossible";
return 0;
}
Compilation message
kitchen.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
29 | main(){
| ^~~~
kitchen.cpp: In function 'int main()':
kitchen.cpp:39:6: warning: unused variable 'ans' [-Wunused-variable]
39 | int ans = mod;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |