# Game Start(https://www.codechef.com/SMCC2021/problems/GAME01)

Practice

Author: Sachin Singh
Tester: Sachin Singh
Editorialist: Sachin Singh

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

Math .

# PROBLEM:

CodeMaster has two boxes. Boxes are filled with different/same size of multiple balls(Natural number writtten on them).First box has N Balls and Second box has M balls.

CodeMaster starts the game and he choose only those ball which is unique(Occurring only once) in both boxes and it’s size divisible by 3.

Help the CodeMaster to print these balls in ascending order. if it is not possible to find unique ball then print -1.

# QUICK EXPLANATION:

Consider You have to given two boxes with N and M balls respectively.we have to print only those element which are divisible 3 and those element which is divisible by 3 must be unique in both. print those in ascending order.

# EXPLANATION:

You have given N and M ball. consider in box A N balls and box B contain M balls.
let’s consider A box has elements [3 4 6 3 6 9] and B box has elements [3 6 12 9 10.]
In box A [3,3,6,6,9] and box B [3,6,9,12] is divisible by 3. But the output contain only 9
because in A box 3 and 6 occurs 2 times so 3 and 6 cant’t be output. In box B element 12 occurs but not in Box A so it also can not be output.

so output is 9 because it occurs in boths boxes only one times.

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int a[n],b[m],c[1005]={0},d[1005]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
for(int i=0;i<n;i++)
{
int k=a[i];
c[k]++;
}
for(int i=0;i<m;i++)
{
int k=b[i];
d[k]++;
}
int j=min(m,n);
//cout<<j<<endl;
int l=0;
for(int i=0;i<1000;i=i+3)
{
if(c[i]==1)
{
if(d[i]==1)
{
cout<<i<<" “;
l=1;
}
}
}
if(l==0)
{
cout<<”-1";
}
cout<<endl;
}
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int a[n],b[m],c[1005]={0},d[1005]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
for(int i=0;i<n;i++)
{
int k=a[i];
c[k]++;
}
for(int i=0;i<m;i++)
{
int k=b[i];
d[k]++;
}
int j=min(m,n);
//cout<<j<<endl;
int l=0;
for(int i=0;i<1000;i=i+3)
{
if(c[i]==1)
{
if(d[i]==1)
{
cout<<i<<" “;
l=1;
}
}
}
if(l==0)
{
cout<<”-1";
}
cout<<endl;
}
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
int a[n],b[m],c[1005]={0},d[1005]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
cin>>b[i];
}
for(int i=0;i<n;i++)
{
int k=a[i];
c[k]++;
}
for(int i=0;i<m;i++)
{
int k=b[i];
d[k]++;
}
int j=min(m,n);
//cout<<j<<endl;
int l=0;
for(int i=0;i<1000;i=i+3)
{
if(c[i]==1)
{
if(d[i]==1)
{
cout<<i<<" “;
l=1;
}
}
}
if(l==0)
{
cout<<”-1";
}
cout<<endl;
}
}