QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125459 | #5137. Tower | SnowNorth | WA | 76ms | 3432kb | C++14 | 867b | 2023-07-16 18:36:50 | 2023-07-16 18:36:53 |
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) {
vector<int> val;
ll cost = 0;
for (int i = 1; i <= n; i++) {
ll tmp = 0;
int x = a[i];
while (x / 2 >= v) {
tmp++;
x /= 2;
}
tmp += abs(x - v);
val.push_back(tmp);
cost += tmp;
}
sort(val.begin(), val.end(), greater<int>());
for (int i = 0; i < m; i++) cost -= val[i];
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: 0ms
memory: 3432kb
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: 76ms
memory: 3432kb
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:
485 3 483 116 617 663 1057 241 678 55
result:
wrong answer 1st numbers differ - expected: '454', found: '485'