QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125435 | #5137. Tower | SnowNorth | WA | 100ms | 3456kb | C++14 | 953b | 2023-07-16 18:09:24 | 2023-07-16 18:09:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
using ll = long long;
int a[N];
void solve() {
int n, m;
vector<int> vec;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int x = a[i];
while (x > 0) {
vec.push_back(x);
x >>= 1;
}
}
ll ans = 1e18;
for (auto v : vec) {
ll cost = 0;
priority_queue<int> q;
for (int i = 1; i <= n; i++) {
int now = a[i], tmp = 0;
while (now / 2 >= v) {
tmp++;
now /= 2;
}
while (now * 2 <= v) {
tmp++;
now *= 2;
}
tmp += abs(now - v);
q.push(tmp);
cost += tmp;
}
for (int i = 0; i < m; i++) {
if (q.empty()) break ;
cost -= q.top();
q.pop();
}
ans = min(ans, cost);
}
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
input:
3 2 0 2 6 5 0 1 2 3 4 5 5 3 1 2 3 4 5
output:
2 4 1
result:
ok 3 number(s): "2 4 1"
Test #2:
score: -100
Wrong Answer
time: 100ms
memory: 3456kb
input:
10 272 118 11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...
output:
480 3 480 110 599 659 1050 241 673 53
result:
wrong answer 1st numbers differ - expected: '454', found: '480'