﻿ D1. Equalizing by Division (easy version) bet356体育下载_bet356客服邮箱_bet356官网

# D1. Equalizing by Division (easy version)

2019-08-31 15:42:55??阅读：130??来源： 互联网

The only difference between easy and hard versions is the number of elements in the array.
You are given an array a consisting of n integers. In one move you can choose any ai and divide it by 2 rounding down (in other words, in one move you can set ai:=?ai2?).
You can perform such an operation any (possibly, zero) number of times with any ai.
Your task is to calculate the minimum possible number of operations required to obtain at least k equal numbers in the array.
Don’t forget that it is possible to have ai=0 after some operations, thus the answer always exists.

Input
The first line of the input contains two integers n and k (1≤k≤n≤50) — the number of elements in the array and the number of equal numbers required.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤2?105), where ai is the i-th element of a.

Output
Print one integer — the minimum possible number of operations required to obtain at least k equal numbers in the array.

Examples
inputCopy
5 3
1 2 2 4 5
outputCopy
1
inputCopy
5 3
1 2 3 4 5
outputCopy
2
inputCopy
5 3
1 2 3 3 3
outputCopy
0

``````#include
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
int n,k;
scanf("%d %d",&n,&k);
for(int i=0;i>a[i];
vector v;
for(int i=0;i0)
{
v.push_back(x);
x/=2;
}
}
int ans=1e9+10;
for(auto res:v)
{
vector cnt;
for(int i=0;ires)
{
x/=2;
cur++;
}
if(x==res) cnt.push_back(cur);
}
if(cnt.size()``````