June Lunchtime 2020 MAXAND18

Subtask #2: Accepted
but
Subtask #1: WA
Can you please tell me what is wrong and how to solve Subtask #1…!!!

void solve()
{
fast;
multimap<ll,ll,greater>mp;
ll n,k;
cin>>n>>k;
ll a[n],max=0;
input(a,n);
int i;
for(i=0;i<=32;i++)
{
ll sum=0;
ll sb=1LL<<i;
for(ll j=0;j<n;j++) sum+=(ll)sb&a[j];
mp.insert(make_pair(sum,i));
}
ll ans=0;
multimap<ll,ll,greater>::iterator it;
for(it=mp.begin();it!=mp.end() && k>0;it++,k–) ans+=(ll)1LL<<(it->second);
cout<<ans<<endl;
return;
}

It would be very helpfull
please can someone see my code i am also following the same approach
my code---->
https://www.codechef.com/viewsolution/35109239

You should iterate over 30 bits instead of 32. I’m don’t know how you even got partial.

that’s the problem subtask 1 can be easily solved. but instead of that subtask2 is completely solved and subtask1 is WA…

1 Like

Not necessarily. The same thing happened to me.
Subtask 1 WA: CodeChef: Practical coding for everyone
AC: CodeChef: Practical coding for everyone