Name string

#codeifyoucansolve
Name string is a string consisting of letters “R”,”K” and “V”. Today Oz wants to design a name string in a beautiful manner. Actually Oz cannot insert these three letters arbitrary anywhere ,he has to follow some rules to make the name string look beautiful. First thing is that the name string should consist of at most two different letters. Secondly adjacent letters in name string must be different.

After this procedure Oz wants name string to be as long as possible. Given the number of “R”,”K” and “V” letters that you have initially ,help Oz to find the maximum length of name string that Oz can make.

Input :
The first line contains the number of test cases T . Each test case consists of three space separated integers – A,B and C representing number of “R” letters, number of “K” letters and number of “V” letters respectively.

Output :
For each test case T, output maximum length of name string that Oz can make.

Constraints :
1 <= T <=100
0 <= A,B,C <=106
Sample Input (Plaintext Link)

2
1 2 5
0 0 2

Sample Output (Plaintext Link)

5
1

Explanation
For first sample :
The longest name string possible is : VKVKV using 3 “V” letters and 2 “K” letters and its length is 5.

#include <stdio.h>

int main()
{
	int T;
	long int A[3],tmp,i,j;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%ld%ld%ld",&A[0],&A[1],&A[2]);
		 for(i=0;i<2;i++)
		 {
		 	for(j=i+1;j<3;j++)
		 	{
		 		if(A[j] > A[i])
		 		{
		 			tmp =A[i];
		 			A[i] = A[j];
		 			A[j] = tmp;
		 		}
		 	}
		 }
		 //for(i=0;i<3;i++)
		   //printf("%d ",A[i]);
		 if(A[0] == 1 && A[1] == 0)
		     printf("1\n");
		 else if(A[0] == 1 && A[1] == 1)
		     printf("2\n");
		 else if(A[0] <= 0)
		     printf("0\n");
		else
			 printf("%ld\n",2*A[1]+1);
		  
	}
    return 0;
}

Compile & Run : https://ideone.com/AeC9hL
Follow on Twitter : https://twitter.com/codeifucansolve
Follow on Quora : http://codeifyoucansolve.quora.com/Name-string