Codeforces “ 1206B – Make Product Equal One” solution( Bangla ) | Cpp language

**Before watching this make sure that you’ve tried enough**

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a;
    cin>>a;
    ll arr[a];
    ll minus=0;
    ll zero=0;
    for(ll i=0;i<a;i++)
    {
        cin>>arr[i];
        if(arr[i]<0)
        {
            minus++;
        }
        if(arr[i]==0) zero++;
    }
    ll cnt=0;
    sort(arr,arr+a);
    if(minus%2==0)
    {
        for(ll i=0;i<a;i++)
        {
            if(arr[i]<0) cnt+=abs(arr[i]+1);
            else cnt+=abs(arr[i]-1);
        }
        cout<<cnt<<endl;
    }
    else
    {
        cnt+=abs(arr[0]-1);
        for(ll i=1;i<a;i++)
        {
            if(arr[i]<0) cnt+=abs(arr[i]+1);
            else cnt+=abs(arr[i]-1);
        }
        if(zero>0)
            cout<<cnt-2;
        else
        cout<<cnt<<endl;

    }

}

 

If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.

More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment