Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*BISMILLAH
- THE WHITE WOLF
- NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef pair<int, int> pii;
- typedef vector<long long> vll;
- typedef vector<int> vi;
- #define io ios_base::sync_with_stdio(false)
- #define pb push_back
- #define eb emplace_back
- #define mod 998244353
- #define PI 2*acos(0.0)
- int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};
- //=============================================ASIFAZAD==============================================//
- bool cmp(pair<ll, int>& a, pair<ll, int>& b)
- {
- if(a.first == b.first)
- return a.second < b.second;
- return a.first > b.first;
- }
- int32_t main()
- {
- io;
- int t;
- cin>>t;
- while(t--)
- {
- int n, k;
- cin>>n>>k;
- vi cnt(35);
- for(int i = 0; i< n; i++)
- {
- int x, j = 0;
- cin>>x;
- while(x)
- {
- cnt[j++] += (x&1);
- x/= 2;
- }
- }
- vector<pair<ll, int> > ck;
- for(int i = 0; i< 31; i++)
- {
- ll v = cnt[i] * ceil(pow(2, i));
- ck.pb({v, i});
- }
- sort(ck.begin(), ck.end(), cmp);
- int x = 0;
- for(int i = 0; i< k; i++)
- x += ceil(pow(2, ck[i].second));
- cout<<x<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment