 # [Solved] Regarding codeforces contest #748

code problem link : Problem - A - Codeforces
Regarding this problem,i have solved using brute force approach using if else statements with all possible condition i have encountered .

``````int solve()
{
int n = 3;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}

ll maxi = *max_element(arr, arr + n);
ll cnt = count(arr, arr + n, maxi);

if (cnt == 3)
cout << "1" << " " <<  "1" << " " << "1" << endl;
else if (cnt == 2)
{
if (maxi == arr and arr == maxi)
{
cout << (maxi)-arr + 1 << " "
<< "1"
<< " "
<< "1" << '\n';
}
if (maxi == arr and arr == maxi)
{
cout << "1"
<< " " << maxi - arr + 1 << " "
<< "1" << '\n';
}
if (maxi == arr and arr == maxi)
{
cout << "1"
<< " "
<< "1"
<< " " << maxi - arr << '\n';
}
}
else
{
if (maxi == arr)
{
cout << (maxi)-arr << " " << maxi - arr + 1 << " " << maxi - arr + 1 << '\n';
}
if (maxi == arr)
{
cout << (maxi)-arr + 1 << " " << maxi - arr << " " << maxi - arr + 1 << '\n';
}
if (maxi == arr)
{
cout << (maxi)-arr + 1 << " " << maxi - arr + 1 << " " << maxi - arr << '\n';
}
}
}

int main()
{
tc
solve();
}
``````

I am not find out my mistake.

1
5 5 2
Yours : 1 1 3
Correct: 1 1 4

1 Like

else if (cnt == 2)
{
if (maxi == arr and arr == maxi)
{
cout << (maxi)-arr + 1 << " "
<< “1”
<< " "
<< “1” << ‘\n’;
}
if (maxi == arr and arr == maxi)
{
cout << “1”
<< " " << maxi - arr + 1 << " "
<< “1” << ‘\n’;
}
if (maxi == arr and arr == maxi)
{
cout << “1”
<< " "
<< “1”
<< " " << maxi - arr << ‘\n’;
}
}

In else if for cnt == 2, check output for 3rd if condition : if (maxi == arr and arr == maxi),
you wrote maxi - arr . Here you forgot to add 1 . Thus it should be maxi-arr+1. Hopw this help.

1 Like

such a kind person you are thank you so much.<3

i got it thank you for pointing it out

You don’t really have to go that far.

for the first it’s max(0, max(b,c) - a).
for the second it’s max(0, max(a,c) - b)
You can figure out the third.

1 Like