QUESTION
Monk and Monk decided to play a simple number game. Each of them had a set of numbers (may contain a number more than once) to play with. Lets denote by A[] the set belonging to Monk, and by B[], the set belonging to Monk.\n\nThey defined three functions f(x) , g(x) and V(x) :\nf(x) : Returns count of numbers strictly smaller than xx in opponent’s set\ng(x): Returns count of numbers strictly greater than xx in opponent’s set\nV(x): f(x)*g(x)\n\nScore of a player is defined to be the V(x) for each element x present in the players set.\nThe player with higher score wins the game.\n\nInput: \n\tThe first line contains two positive integers N and M where N and M represent the number of elements present in Monk and !Monk’s sets respectively.\n\n\tThe second line contains N space separated integers – elements present in Monk’s set\n\tThe third line contains M space separated integers – elements present in !Monk’s set\n\nOutput:\n\tIf Monk wins, print \”Monk\” (without quotes) followed by a space and the score difference between him and !Monk\n\tIf !Monk wins, print \”!Monk\” (without quotes) followed by a space and the score difference between him and Monk\n\tIf both players have equal scores, then print \”Tie\” (without quotes).\n\n\nSAMPLE INPUT\n2 2 \n1 3 \n0 5 \nSAMPLE OUTPUT\nMonk 2\n\n3 3\n79837 255435 511328 \n329397 184646 135804\n\nSAMPLE OUTPUT\n!Monk 4\n.
“TESTCASE_1”: “2 2\n1 3\n0 5\n###—###SEPERATOR—###—\nMonk 2”, “TESTCASE_2”: “4 5\n2 3 6 8\n5 7 9 12 18\n###—###SEPERATOR—###—\nMonk 3”, “TESTCASE_3”: “3 3\n79837 255435 511328 \n329397 184646 135804\n###—###SEPERATOR—###—\n!Monk 4”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0
ANSWER
#include<stdio.h>
long int funcf(long int temp,long int a[' '],long int n)
{
long int i,j;
long int c=0;
for(i=0;i<n;i++)
{
if(a[i] < temp)
c++;
}
return c;
}
long int funcg(long int temp,long int a[' '],long int n)
{
long int i,j;
long int c=0;
for(i=0;i<n;i++)
{
if(a[i]>temp)
c++;
}
return c;
}
int main()
{
long int n,m,i,j,sm=0,snm=0;
long int mon[' '],nmon[' '];
scanf("%ld%ld",&n,&m);
for(i=0;i<n;i++)
scanf("%ld",&mon[i]);
for(i=0;i<m;i++)
scanf("%ld",&nmon[i]);
for(i=0;i<n;i++)
{
sm=sm+(funcf(mon[i],nmon,m)*funcg(mon[i],nmon,m));
}
for(i=0;i<m;i++)
{
snm=snm+(funcf(nmon[i],mon,n)*funcg(nmon[i],mon,n));
}
if(sm>snm)
{
printf("Monk %ld",sm-snm);
}
else if(snm>sm)
{
printf("!Monk %ld",snm-sm);
}
else
{
printf("Tie");
}
return 0;
}