 # AIRTEL I code lessen sum

This post was flagged by the community and is temporarily hidden.

Will post its solution once test time gets over.

1 Like

@ayanujju I couldn’t solve the ‘queries on expression’ problem. Were you able to solve both the problems? Will they only call those who have solved both?

can you post it now?

Yes. I don’t know what will be the eligibility criteria but as per the trend, it seems like they’ll be selecting only those candidates who solved both.

Sure. Here you go.

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

public:
ll a,b;
Pair(ll a, ll b)
: a(a), b(b)
{
}
};

bool operator<(const Pair& p1, const Pair& p2)
{
return p2.a*(p2.b-p2.b/2)>p1.a*(p1.b-p1.b/2);
}

void fun(ll a[],ll b[],int n,ll k)
{
int i,j;
ll s=0,s1;
priority_queue Q,Q1;
for(i=0;i<n;i++)
{
s+=a[i]b[i];
Q.push(Pair(a[i],b[i]));
Q1.push(Pair(b[i],a[i]));
}
s1=s;
j=0;
while(s>k)
{
Pair p=Q.top();
s-=p.a
(p.b-p.b/2);
p.b/=2;
Q.pop();
Q.push§;
j++;
}
i=0;
while(s1>k)
{
Pair p=Q1.top();
s1-=p.a*(p.b-p.b/2);
p.b/=2;
Q1.pop();
Q1.push§;
i++;
}
if(i>j)
cout<<“Alice\n”;
else if(i<j)
cout<<“Bob\n”;
else
cout<<“Tie\n”;
}
int main()
{
int t,n,i;
ll a,b,k;
cin>>t;
while(t–)
{
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
cin>>b[i];
cin>>k;
fun(a,b,n,k);
}
return 0;
}