//Note:-BAD ALGORITHM
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder("");
int testcase=Integer.parseInt(br.readLine());
String playersname[]=new String[10];
int playersability[][]=new int[10][2];
for (int i = 0; i < testcase; i++)
{
for (int j = 0; j < 10; j++)
{
String s[]=br.readLine().split(" ");
playersname[j]=s[0];
playersability[j][0]=Integer.parseInt(s[1]);
playersability[j][1]=Integer.parseInt(s[2]);
}
int max=0;
boolean isattacker[]=new boolean[10];
for (int b =0; b < 10-4; b++)
{
for (int c =b+1;c<10-3; c++)
{
for (int d =c+1;d<10-2; d++)
{
for (int e=d+1;e<10-1; e++)
{
for (int f =e+1; f<10; f++)
{
int totalattack=playersability[b][0]+playersability[c][0]+playersability[d][0]+playersability[e][0]+playersability[f][0];
if(totalattack>max)
{
for (int j = 0; j < isattacker.length; j++)
{
isattacker[j]=false;
}
isattacker[b]=true;
isattacker[c]=true;
isattacker[d]=true;
isattacker[e]=true;
isattacker[f]=true;
max=totalattack;
}
else if(totalattack==max)
{
int totaldefence=0;
int olddefence=0;
for (int j = 0; j < isattacker.length; j++)
{
if(!isattacker[j])
{
olddefence+=playersability[j][1];
}
}
for (int j = 0; j < playersability.length; j++)
{
if(j!=b && j!=c && j!=d && j!=e && j!=f)
totaldefence+=playersability[j][1];
}
if(olddefence0)
{
//ans a1
for (int j1 = 0; j1 < isattacker.length; j1++)
{
isattacker[j1]=false;
}
isattacker[b]=true;
isattacker[c]=true;
isattacker[d]=true;
isattacker[e]=true;
isattacker[f]=true;
max=totalattack;
break;
}
}
}
}
}
}
}
}
}
String attackers[]=new String[5];
String defender[]=new String[5];
int t=0,q=0;
for (int j = 0; j < isattacker.length; j++)
{
if(isattacker[j])
{
attackers[t++]=playersname[j];
}
else
defender[q++]=playersname[j];
}
Arrays.sort(attackers);
Arrays.sort(defender);
sb.append("Case "+(i+1)+":\n");
sb.append("("+attackers[0]);
for (int j = 1; j < attackers.length; j++)
{
sb.append(", "+attackers[j]);
}
sb.append(")\n");
sb.append("("+defender[0]);
for (int j = 1; j < defender.length; j++)
{
sb.append(", "+defender[j]);
}
sb.append(")\n");
}
System.out.print(sb);
}
}
0 comments: