-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathD.java
More file actions
143 lines (120 loc) · 3.54 KB
/
D.java
File metadata and controls
143 lines (120 loc) · 3.54 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.io.*;
import java.math.*;
import java.util.*;
public class D {
public static void main(String[] args) {
try {
(new Solver()).go();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
class Solver {
TreeMap<Pair, Integer> f = new TreeMap<>();
TreeMap<Pair, Integer> trace = new TreeMap<>();
public void go() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n = in.nextInt();
int[] a = new int[n];
int[] b = new int[n];
int[] c = new int[n];
int res = 0;
int save1 = -1, save2 = -1;
for(int i = 0; i < n; i++) {
a[i] = in.nextInt();
b[i] = in.nextInt();
c[i] = in.nextInt();
int cur = min3(a[i], b[i], c[i]);
if (cur > res) {
res = cur;
save1 = i;
save2 = -1;
}
int t = get(a[i], b[i], c[i]);
if (t > res) {
res = t;
save1 = i;
save2 = trace.get(new Pair(b[i], c[i]));
}
t = get(b[i], c[i], a[i]);
if (t > res) {
res = t;
save1 = i;
save2 = trace.get(new Pair(c[i], a[i]));
}
t = get(c[i], a[i], b[i]);
if (t > res) {
res = t;
save1 = i;
save2 = trace.get(new Pair(a[i], b[i]));
}
update(a[i], b[i], c[i], i);
update(b[i], c[i], a[i], i);
update(c[i], a[i], b[i], i);
}
save1 += 1;
if (save2 >= 0) {
save2 += 1;
out.println(2);
out.println(save1 + " " + save2);
}
else {
out.println(1);
out.println(save1);
}
out.close();
}
int get(int a, int b, int c) {
Pair t = new Pair(b, c);
if (f.containsKey(t)) {
return min3(a + f.get(t), b, c);
}
else return -1;
}
void update(int a, int b, int c, int id) {
Pair t = new Pair(b, c);
if (!f.containsKey(t) || f.get(t) < a) {
f.put(t, a);
trace.put(t, id);
}
}
int min3(int a, int b, int c) {
return Math.min(a, Math.min(b, c));
}
}
class Pair implements Comparable<Pair> {
public int x, y;
public Pair(int x, int y) {
this.x = Math.min(x, y);
this.y = Math.max(x, y);
}
public int compareTo(Pair a) {
if (x != a.x) return x - a.x;
return y - a.y;
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}