-
Notifications
You must be signed in to change notification settings - Fork 0
/
worms-evolution.java
61 lines (49 loc) · 1.55 KB
/
worms-evolution.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
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class NewProg {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int [] arr = new int[n];
int a = 0;
int b = 0;
int c = 0;
boolean flag = false;
for (int i = 0; i<n; i++){
arr[i] = sc.nextInt();
}
mainLoop:
for (int i = 0; i<n-2; i++){
for (int j = i+1; j<n-1; j++){
for (int k = j+1; k<n; k++){
if (arr[i] + arr[j] == arr[k] || arr[j] + arr[k] == arr[i] || arr[k] + arr[i] == arr[j]){
flag = true;
if (arr[i] > arr[j] && arr[i] > arr[k]){
a = k+1;
b = j+1;
c = i+1;
}
else if (arr[j] > arr[i] && arr[j] > arr[k]){
a = k+1;
b = i+1;
c = j+1;
}
else{
a = i+1;
b = j+1;
c = k+1;
}
break mainLoop;
}
}
}
}
if (flag){
System.out.println(c + " " + a + " "+ b);
}
else {
System.out.println(-1);
}
}
}