#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;
#define IMPOSSIBLE {cout<<"Impossible"<<endl;return 0;}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, k; cin>>n>>m>>k;
vector<int> a(n);
int s = 0;
for(int&i : a){
cin>>i;
if(i < k)IMPOSSIBLE
s += i;
}
vector<int> b(m);
for(int&i : b){
cin>>i;
}
int ans = 1e9;
for(int mask = 0; mask < (1<<m); mask++){
int sb = 0, sbc = 0;
for(int i = 0; i < m; i++){
if((mask>>i)&1){
sb += b[i];
sbc += min(b[i], n);
}
}
if(sb < s)continue;
if(sbc < k*n)continue;
ans = min(ans, sb-s);
}
if(ans == 1e9)cout<<"Impossible"<<endl;
else cout<<ans<<endl;
// int n, m, k; cin>>n>>m>>k;
// int s = 0;
// for(int i = 0; i < n; i++){
// int a; cin>>a;s += a;
// }
// vector<bool> v(90001);
// v[0] = true;
// int mx = 1e9;
// for(int i = 0; i < m; i++){
// int b; cin>>b;
// for(int j = 90000; j-b >= 0; j--){
// if(v[j-b])v[j]=true;
// if(v[j] && j >= s){
// mx = min(mx, j);
// }
// }
// }
// if(mx == 1e9)IMPOSSIBLE
// else {
// cout<<mx-s<<endl;
// }
// int n, m, k; cin>>n>>m>>k;
// vector<int> a(n);
// int s = 0;
// for(int&i:a){cin>>i;s += i;}
// vector<int> b(m);
// int sb = 0;
// for(int&i:b){cin>>i;sb += i;}
// if(k > m) IMPOSSIBLE
// for(int i : a){
// if(i < k) IMPOSSIBLE;
// }
// if(s > sb) IMPOSSIBLE;
// if(m == 1){
// cout<<sb - s<<endl;
// return 0;
// }
// if(k == 2){
// if(b[0] < n || b[1] < n)IMPOSSIBLE
// cout<<b[0]+b[1]-s<<endl;
// } else {
// int egy = min(b[0], b[1]);
// if(egy < s) cout<<sb-s<<endl;
// else cout<<egy-s<<endl;
// }
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
3 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
316 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
3 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |