-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEqualizing_by_Division_easy_version.cpp
More file actions
64 lines (47 loc) · 1.13 KB
/
Equalizing_by_Division_easy_version.cpp
File metadata and controls
64 lines (47 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// https://codeforces.com/contest/1213/problem/D1
#define DEBUG
#define MAXN 1e9+10
#include <bits/stdc++.h>
using namespace std;
int main ()
{
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
int n, k;
cin >> n >> k;
vector<int > a;
for (int i = 0; i < n; ++i) {
int temp;
cin >> temp;
a.push_back(temp);
}
// guess target number
vector<int > possible;
for (int i = 0; i < n; ++i) {
int x = a[i];
while (x > 0) {
possible.push_back(x);
x/=2;
}
}
// try divide
int ans = MAXN;
for (auto x : possible) {
vector<int > cnt;
for (int i = 0; i < n; ++i) {
int y = a[i], count = 0;
while (x < y) {
y/=2;
count++;
}
if (y == x ) cnt.push_back(count);
}
if (int(cnt.size() < k)) continue;
sort(cnt.begin(), cnt.end());
ans = min(ans, accumulate(cnt.begin(), cnt.begin()+k, 0));
}
cout << ans << endl;
return 0;
}