[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[1] and arr[2] == maxi)
        {
            cout << (maxi)-arr[0] + 1 << " "
                 << "1"
                 << " "
                 << "1" << '\n';
        }
        if (maxi == arr[0] and arr[2] == maxi)
        {
            cout << "1"
                 << " " << maxi - arr[1] + 1 << " "
                 << "1" << '\n';
        }
        if (maxi == arr[1] and arr[0] == maxi)
        {
            cout << "1"
                 << " "
                 << "1"
                 << " " << maxi - arr[2] << '\n';
        }
    }
    else
    {
        if (maxi == arr[0])
        {
            cout << (maxi)-arr[0] << " " << maxi - arr[1] + 1 << " " << maxi - arr[2] + 1 << '\n';
        }
        if (maxi == arr[1])
        {
            cout << (maxi)-arr[0] + 1 << " " << maxi - arr[1] << " " << maxi - arr[2] + 1 << '\n';
        }
        if (maxi == arr[2])
        {
            cout << (maxi)-arr[0] + 1 << " " << maxi - arr[1] + 1 << " " << maxi - arr[2] << '\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[1] and arr[2] == maxi)
{
cout << (maxi)-arr[0] + 1 << " "
<< β€œ1”
<< " "
<< β€œ1” << β€˜\n’;
}
if (maxi == arr[0] and arr[2] == maxi)
{
cout << β€œ1”
<< " " << maxi - arr[1] + 1 << " "
<< β€œ1” << β€˜\n’;
}
if (maxi == arr[1] and arr[0] == maxi)
{
cout << β€œ1”
<< " "
<< β€œ1”
<< " " << maxi - arr[2] << β€˜\n’;
}
}

In else if for cnt == 2, check output for 3rd if condition : if (maxi == arr[1] and arr[0] == maxi),
you wrote maxi - arr[2] . Here you forgot to add 1 . Thus it should be maxi-arr[2]+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