-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwormsEvolution.cpp
43 lines (40 loc) · 889 Bytes
/
wormsEvolution.cpp
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
/*Professor Vasechkin is studying evolution of worms.
Recently he put forward hypotheses that all worms evolve by division.
There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an.
To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms.
Help him to do this.*/
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
for (int i = 0; i < n; i++)
{
int ele = arr[i];
for (int j = 0; j < n; j++)
{
if (i != j)
{
for (int k = 0; k < n; k++)
{
if (k != i && k != j)
{
if (ele + arr[j] == arr[k])
{
cout << k + 1 << " " << i + 1 << " " << j + 1<< endl;
return 0;
}
}
}
}
}
}
cout << "-1";
return 0;
}