HELP! xxoorr July LOng challenge

Hi
This is my code.

#include

#include

#include

#include

#include

using namespace std;

#define ll long long int

int main() {

ll t;

cin>>t;

while(t–)

{

ll n,k;

cin>>n>>k;

ll a[n];

for(ll i=0;i<n;++i){

    cin>>a[i];

}map<ll,ll> bits;

for(ll i=0;i<n;++i){

    ll k=a[i];

    ll j=33;

    while(k){

        bits[j]+=(k%2);

        k/=2;

        --j;

    }

    

} ll ans=0;

for(ll i=0;i<=33;++i){

    ans+=(ceil(bits[i]/k));

}

cout<<ans<<‘\n’;

}

return 0;

}
This is the problem link.

Where have i gone wrong?

You should convert to bits[i]/k to (double)bits[i]/k type then ceil works otherwise it is same as integer division.
Also use for_each loop for using bits[i] as like this:

for(auto value:bits){
 ans+=ceil((double)value.second/k);
}
1 Like

Okay that worked thank you!