#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
const int maxn5 = 7e3 + 10;
const ll inf = 1e18;
ll a[maxn5], b[maxn5];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n, m, k; cin >> n >> m >> k;
if(m > 16)
return 0;
ll sum = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] < k)
return cout << "Impossible" << endl, 0;
sum += a[i];
}
for(int i = 0; i < m; i++)
cin >> b[i];
ll ans = inf;
for(int mask = 0; mask < (1 << m); mask++) if(__builtin_popcount(mask) >= k){
ll sum1 = 0, sum2 = 0;
for(int i = 0; i < m; i++) if((mask >> i)&1){
sum1 += min(n, b[i]);
sum2 += b[i];
}
if(sum1 >= n * k && sum2 >= sum && ans >= sum2){
ans = sum2;
//cout << mask << ' ' << sum1 << ' ' << sum2 << endl;
}
}
if(ans == inf)
cout << "Impossible" << endl;
else
cout << ans - sum << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
252 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
252 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |