QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125444#5137. TowerSnowNorthWA 86ms3492kbC++14888b2023-07-16 18:25:372023-07-16 18:25:39

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 18:25:39]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:3492kb
  • [2023-07-16 18:25:37]
  • 提交

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;
			}
			
			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: 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: 86ms
memory: 3492kb

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'