THE_WHITE_WOLF

Untitled

Jul 16th, 2020
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. /*BISMILLAH
  2. THE WHITE WOLF
  3. NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/
  4.  
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. typedef long long ll;
  8. typedef unsigned long long ull;
  9. typedef pair<int, int> pii;
  10. typedef vector<long long> vll;
  11. typedef vector<int> vi;
  12.  
  13. #define io ios_base::sync_with_stdio(false)
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define mod   998244353
  17. #define PI 2*acos(0.0)
  18. int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};
  19.  
  20.  
  21. //=============================================ASIFAZAD==============================================//
  22. bool cmp(pair<ll, int>& a, pair<ll, int>& b)
  23. {
  24.     if(a.first == b.first)
  25.         return a.second < b.second;
  26.     return a.first > b.first;
  27. }
  28.  
  29.  
  30. int32_t main()
  31. {
  32.     io;
  33.     int t;
  34.     cin>>t;
  35.     while(t--)
  36.     {
  37.         int n, k;
  38.         cin>>n>>k;
  39.         vi cnt(35);
  40.         for(int i = 0; i< n; i++)
  41.         {
  42.             int x, j = 0;
  43.             cin>>x;
  44.             while(x)
  45.             {
  46.                 cnt[j++] += (x&1);
  47.                 x/= 2;
  48.             }
  49.         }
  50.         vector<pair<ll, int> > ck;
  51.         for(int i = 0; i< 31; i++)
  52.         {
  53.             ll v = cnt[i] * ceil(pow(2, i));
  54.             ck.pb({v, i});
  55.         }
  56.         sort(ck.begin(), ck.end(), cmp);
  57.         int x = 0;
  58.         for(int i = 0; i< k; i++)
  59.             x += ceil(pow(2, ck[i].second));
  60.         cout<<x<<"\n";
  61.     }
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment