JUNE LUNCHTIME MAX AND

Below code providing me 50 marks , just the last one in 2nd subtask in giving WA, is there any corner case left to be handled…

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

void fun(ll n,ll count[32])
{
ll c=0;
while(n)
{
if(n&1)
{
count[c]++;
}
n>>=1;
c++;
}
}

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];
}

	vector<pair<ll,ll>> v;
		ll vari[32]={0};
		
		for(ll i=0;i<n;i++)
			fun(a[i],vari);

		for(ll i=0;i<32;i++)
			vari[i]*=(ll)pow(2,i);
        for(ll i=0;i<32;i++)
			{v.push_back({vari[i],i});}
		
		sort(v.begin(),v.end());	
//         for(long i=0;i<32;i++)
			// cout<<v[i].first<<" "<<v[i].second<<endl;
			
			ll cnt_mx=0;
			map<ll,ll> nw;
	        for(ll i=0;i<32;i++)
			{  if(v[i].first>0){cnt_mx++; nw[v[i].first]++;  } }		
			
	int vis[32]={0};		
		vector<ll> inx;
		int fg=0;
		if(cnt_mx<=k){
		    for(ll i=v.size()-1;i>=0;i--){
		        if(v[i].first==0){break;}
		        inx.push_back(v[i].second);k--;
		        vis[v[i].second]=1;
		    }
		    for(ll i=0;i<32;i++){
		        if(k==0)break;
		        if(vis[i]==0){
		        inx.push_back(i);
		        k--;
		        }
		    }
		}
		else{
		   for(ll i=v.size()-1;i>=0;i--){
		        if(k==0){break;}
	            if(nw[v[i].first]>k){
	               vector<int> res;
	               for(ll j=i;j>=0;j--){
	                   if(v[i].first==v[j].first){
	                       res.push_back(v[j].second);
	                   }
	               }
	               sort(res.begin(),res.end());
	               for(ll lp=0;lp<res.size();lp++){
	                   if(k==0)break;
	                inx.push_back(res[lp]);k--;     
	               }
	             break;  
	            } 
		        inx.push_back(v[i].second);
		        k--;
		    }
		}
		
        
	    ll final=0;
	   
	   for(ll ui:inx){
	       //cout<<ui<<" ";
	       final+=pow(2,ui);
	   } 
	    cout<<final<<endl;
     
}
return 0;

}

You could have pasted the link.

1 Like

i thought primary concern should be on getting the answer…

I mean you should have pasted the link which is easy to find errors.

Although I used long long ,I got 50 points only.
Please find my error.
https://www.codechef.com/viewsolution/34803017

Made minor changes to your code. You dont have to keep a track for 64 bits. 30 bits are enough.
AC Code

1 Like

Thank you Robosapien .