In this

**HackerEarth The Final Quiz problem solution**You, Bob, and Alice are playing a quizzing game. Throughout the game, you and the other two competitors have gained some points. Now at the end of the game, the three of you are given a final question. Before you hear the question you have to guess some special points.If a contestant answers the question correctly he/she will be awarded the points equal to the special points he guessed and the same amount of points (he guessed ) will be deducted in case of a wrong answer. The participant who ends up with the highest score after the final question will end up winning the game.

Now it is time for you to guess your special points. You can bet any amount between 0 and your current score, both inclusive. You are given your current scoreX followed by the current scores of AliceY and BobZ. You are also given special points guessed by Alice A and special points guessed by Bob B. You have to guess your special points, which maximizes your probability of winning the Quiz.

You can assume that you and both the other participants each independently have a 50% chance to answer correctly. If multiple special points can give you the highest probability of winning, choose the minimum one.

## HackerEarth The Final Quiz problem solution.

```
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int a,a1,a2,b1,b2;
cin>>a>>a1>>a2>>b1>>b2;
assert(1<=a&&a<=100000);
assert(1<=a1&&a1<=100000);
assert(1<=a2&&a2<=100000);
assert(0<=b1&&b1<=a1);
assert(0<=b2&&b2<=a2);
int mi=-1;
int ans=1234567;
for(int i=0;i<=a;i++)
{
int x=a-i;
int y=a+i;
int x1=a1-b1;
int x2=a2-b2;
int y1=a1+b1;
int y2=a2+b2;
int c=0;
if(x>x1&&x>x2)
c++;
if(x>x1&&x>y2)
c++;
if(x>y1&&x>x2)
c++;
if(x>y1&&x>y2)
c++;
if(y>x1&&y>x2)
c++;
if(y>x1&&y>y2)
c++;
if(y>y1&&y>x2)
c++;
if(y>y1&&y>y2)
c++;
if(c>mi)
{
mi=c;
ans=i;
}
}
cout<<ans<<"\n";
}
return 0;
}
```

## 0 Comments