-
Notifications
You must be signed in to change notification settings - Fork 22
/
RESCALC.java
70 lines (70 loc) · 2.09 KB
/
RESCALC.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.*;
import java.util.*;
class RESCALC
{
public static void main(String[] ar)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int t = Integer.parseInt(br.readLine());
while(t-->0)
{
int n = Integer.parseInt(br.readLine()),max=0,c1=0,p=0;
for(int j=0;j<n;j++)
{
String[] s = br.readLine().split(" ");
int m = Integer.parseInt(s[0]),sum=m;
int count[] = new int[7];
ArrayList<Integer> al = new ArrayList<Integer>();
for(int i=1;i<=m;i++)
count[Integer.parseInt(s[i])]++;
for(int i=1;i<7;i++)
if(count[i]>0)
al.add(count[i]);
int len=al.size();
while(true)
{
int c=0;
for(int i=0;i<len;i++)
{
if(al.get(i)>0)
{
int q = al.get(i);
al.set(i,--q);
c++;
}
}
if(c==4)
sum+=1;
else if(c==5)
sum+=2;
else if(c==6)
sum+=4;
else
break;
}
if(sum>=max)
{
if(sum==max)
c1++;
else
{
max=sum;
p=j+1;
c1=0;
}
}
}
if(c1>0)
out.println("tie");
else
{
if(p==1)
out.println("chef");
else
out.println(p);
}
out.flush();
}
}
}