CC001 - Editorial

Contest Name:

CODICTION 2020

PROBLEM LINK:

Problem
Contest

Author: Anshul Bhatia
Tester: Mradul Rathore, Nehal Jain, Saniya Agrawal
Editorialist: Murtaza Ali, Nehal Jain

DIFFICULTY:

CAKEWALK.

PREREQUISITES:

Basic Mathematics.

PROBLEM:

Find the maximum number of roses which can be exchanged between the boys and the girls. The exchange can take place if and only if at least one of them hasn’t received a rose from anyone else.

Roses can only be exchanged once.

QUICK EXPLANATION:

The easiest solution is to choose one boy to give roses to every girl and choose one girl to give roses to every other boy (other than the previous boy).

EXPLANATION:

At first,let us consider a boy.
He is eligible to exchange roses with all the G girls. Hence, he will exchange G roses with G girls (one rose to each). Each exchange requires 2 roses.
Therefore, total roses required = 2 * G

Now, lets consider a girl.
She has already exchanged roses once (with the first boy). Therefore she can only exchange roses with the other B - 1 boys. Each exchange requires 2 roses.
Therefore, total roses required = 2 * (B - 1)

After this exchange, all boys and girls will have exchanged roses at least once.

Total roses required = 2 * G + 2 * (B - 1) = 2 * (B + G - 1)

COMPLEXITY:

Time complexity: O(1) per test.

SOLUTIONS:

Setter's Solution
#include <iostream>
using namespace std;

int main() {
    int t;
    cin>>t;
   	while(t--){
        long b, g;
        cin>>b>>g;
        cout<<2 * (b + g - 1)<<'\n';
    }
    return 0;
}

Feel free to share your approach. If you have any queries, they are always welcome.