We need to solve: given sorted array a (non-decreasing), find any triple i<j<k such that a_i, a_j, a_k cannot form a non-degenerate triangle. Condition for triangle inequality: For three sides x ≤ y ≤ z (the sorted values of the triple), triangle is non-degenerate if x + y > z (strictly greater). Degenerate or impossible if x + y ≤ z.
Given array is sorted, so for indices i<j<k, we have a_i ≤ a_j ≤ a_k. So condition for non-degenerate: a_i + a_j > a_k. We want a triple where a_i + a_j ≤ a_k. So essentially we want to find any i<j<k with a_i + a_j ≤ a_k.
If no such triple exists, output -1.
Constraints: sum n ≤ 1e5, per test case up to 5e4. So O(n log n) or O(n) per test case is fine.
We need to output any valid triple indices (1-indexed). So we can find any.
Observation: Since array is sorted, a triple with smallest a_i and a_j but large a_k might work. The condition a_i + a_j ≤ a_k is reminiscent of checking if there's any triple violating triangle inequality. For sorted array, we can check adjacent or near elements? Actually, typical triangle problem: to check if there exists any triple that can form a triangle, we often check consecutive triple: if a_i + a_{i+1} > a_{i+2}? For non-decreasing sorted, if any three consecutive elements satisfy a_i + a_{i+1} > a_{i+2}, then there exists a triangle. But that is for existence of a valid triangle, not for existence of invalid triple. For invalid triple, we want opposite. But maybe we can also consider checking if there exists any i such that a_i + a_{i+1} ≤ a_{something}. However, not necessarily consecutive.
Because we want any triple i<j<k. Since array is sorted, the condition a_i + a_j ≤ a_k is easier to satisfy when i and j are as small as possible and k is as large as possible. But we have constraints i<j<k. So a naive O(n^3) is impossible.
We can try to find if there exists any triple such that a_i + a_j ≤ a_k. Since sorted, we can fix k, then look for i<j<k with a_i + a_j ≤ a_k. To find such pair efficiently, we might check the two smallest elements (i=1, j=2). If a_1 + a_2 ≤ a_k, then triple (1,2,k) works. This is promising. Because if for some k, the sum of the two smallest elements is ≤ a_k, then we have answer. So we can iterate k from 3 to n and check if a_1 + a_2 ≤ a_k. If yes, output (1,2,k). This is O(n) per test case.
But does this guarantee to find a triple if one exists? Not necessarily: there might be a triple that violates triangle but where the two smallest elements (overall) are not the i and j. For example, maybe a_1 + a_2 > a_k for all k, but there exists some other i,j (not necessarily the smallest two) with a_i + a_j ≤ a_k. Consider a case where a_1 is very large? Actually a_1 is smallest. So a_i + a_j is at least a_1 + a_2 (since i and j are distinct smallest indices). But wait: for a fixed k, we need i<j<k. The minimal possible sum among pairs with indices < k is a_1 + a_2 (since sorted). So if for a given k, there exists some pair (i,j) such that a_i + a_j ≤ a_k, then particularly the minimal sum a_1 + a_2 must be ≤ a_i + a_j ≤ a_k? Actually no: If a_i + a_j ≤ a_k, then the minimum sum among all pairs before k is ≤ that sum. So a_1 + a_2 ≤ a_i + a_j ≤ a_k. So a_1 + a_2 ≤ a_k. Therefore, for that k, it's necessary that a_1 + a_2 ≤ a_k. So if there exists any triple violating triangle, then there exists some k such that a_1 + a_2 ≤ a_k? Not necessarily, because the minimal pair sum might be > a_k, but a larger pair sum could be ≤ a_k? That's impossible: If the minimum sum is > a_k, then any larger sum is also > a_k. So indeed, for a given k, if there exists any pair (i,j) with i<j<k satisfying a_i + a_j ≤ a_k, then the minimal sum among all pairs (i<j<k) is ≤ a_i + a_j ≤ a_k. Since the minimal sum is a_1 + a_2 (or maybe a_1 + a_2 if both indices < k? But note that i and j must be < k, so the smallest two elements with indices less than k could be different if k is small. For k=3, the only possible pair is (1,2). For larger k, the minimal pair sum among indices < k is indeed a_1 + a_2, provided both 1 and 2 are < k, i.e., k>2. So for any k≥3, the minimal sum of two distinct elements with indices less than k is a_1 + a_2 because those are the two smallest values overall and their indices are 1 and 2 which are < k for k≥3. So yes, a_1 + a_2 is the absolute minimum sum for any pair i<j<k (since the set of indices <k includes 1 and 2 for k≥3). So if there exists a triple (i,j,k) violating triangle, then for that specific k, we have a_i + a_j ≤ a_k, and since a_1 + a_2 ≤ a_i + a_j, we get a_1 + a_2 ≤ a_k. Therefore, checking condition a_1 + a_2 ≤ a_k for some k≥3 is both necessary and sufficient for existence of some violating triple? It is sufficient because if a_1 + a_2 ≤ a_k, then triple (1,2,k) is violating (since a_1 + a_2 ≤ a_k). However, we must ensure that 1<2<k, which holds for k≥3. So yes, if there exists any violating triple, then a_1 + a_2 ≤ a_k for that particular k, and thus (1,2,k) would also be violating. Wait careful: Suppose there exists triple (i,j,k) with a_i + a_j ≤ a_k. Since i,j < k, and a_1 ≤ a_i, a_2 ≤ a_j (but careful: j could be 2? Actually if i=1, j=2, it's fine. If i is not 1, then a_1 ≤ a_i, a_2 ≤ a_j? But j could be index 2? If i>1, then a_2 might be a_i? Actually if i>1, the smallest two elements among indices <k are a_1 and a_2. However, we need to compare sums: a_1 + a_2 ≤ a_i + a_j? Since a_1 ≤ a_i and a_2 ≤ a_j? Not necessarily: If i=2 and j=3, then a_1 ≤ a_2 and a_2 ≤ a_3? But a_1 + a_2 ≤ a_2 + a_3? That's true because a_1 ≤ a_3? Actually need to verify: For i<j<k, we have a_1 ≤ a_i and a_2 ≤ a_j? But a_2 might be > a_j if j=1? j is > i, so j≥2. The two smallest elements among indices less than k are a_1 and a_2. However, the pair (i,j) might not include a_1 and a_2 together. Could it be that a_i + a_j is actually smaller than a_1 + a_2? Unlikely because a_1 is the absolute minimum, and a_2 is second minimum. For any two distinct indices, the smallest possible sum is indeed a_1 + a_2 (if we pick the two smallest values). But we must consider that i and j must be distinct, but they could be (1,2) themselves. So any other pair will have both numbers at least as large as a_1 and a_2 respectively? Actually if we pick (1,3), sum = a_1 + a_3 which is ≥ a_1 + a_2 (since a_3 ≥ a_2). If we pick (2,3), sum = a_2 + a_3 ≥ a_1 + a_2. So indeed a_1 + a_2 is the minimal possible sum among any two distinct indices. So yes, a_1 + a_j ≥ a_1 + a_2 if j≥2? Actually if we pick (1,2) it's the minimum. So a_1 + a_2 ≤ any a_i + a_j for i≠j. Therefore, if a_i + a_j ≤ a_k for some i,j,k, then a_1 + a_2 ≤ a_i + a_j ≤ a_k, so a_1 + a_2 ≤ a_k. So there exists k such that a_1 + a_2 ≤ a_k. Then (1,2,k) also violates. Therefore, existence of any violating triple is equivalent to existence of k (≥3) with a_k ≥ a_1 + a_2. So we can simply check: if a_1 + a_2 ≤ a_n? Actually we need k>2. So we can check if there exists any k≥3 such that a_k ≥ a_1 + a_2. Since array is non-decreasing, the maximum a_k is a_n. So if a_1 + a_2 ≤ a_n, then we can pick k = n (or the first such k) and output (1,2,k). But careful: need to ensure k>2. a_n is okay if n≥3. So condition simplifies to: if a_1 + a_2 ≤ a_n, then (1,2,n) is a violating triple? Actually check: For triple (1,2,n), we have a_1 + a_2 ≤ a_n (by condition). So it's a violating triple. But is it guaranteed that indices are distinct and ordered? Yes.
Thus algorithm: For each test case, if n < 3? n≥3. Check if a[0] + a[1] <= a[n-1] (1-indexed). If true, output "1 2 n". Else output -1.
But is that always correct? Let's test with sample.
Sample 1: 4 6 11 11 15 18 20. a1=4, a2=6 sum=10. a_n=20, 10 <=20 true => output 1 2 7? But sample output is 2 3 6. Both are valid. Our output would be 1 2 7. That's acceptable because problem says print any of them.
Sample 2: 10 10 10 11. a1=10, a2=10 sum=20, a_n=11, 20 <= 11 false => output -1. Good.
Sample 3: 1 1 1000000000. sum=2, a_n=1e9, 2 <= 1e9 true => output 1 2 3. Good.
So seems trivial! But wait, is there any edge case? For n=3, check a1+a2 <= a3? That's exactly the condition for degenerate triangle. So yes.
What about case where a1+a2 <= a3 but not <= a_n? Actually if a1+a2 <= a3, then a_n is >= a3, so condition holds. So it's same.
But what about when a1 and a2 indices are not both less than k? For k=3, we need i<j<k, so i=1,j=2,k=3 works if a1+a2 <= a3. So fine.
Thus solution: For each test case, if a[0] + a[1] <= a[n-1], print "1 2 n", else print "-1".
But is there any scenario where a1+a2 > a_n, yet there exists some other triple violating? Suppose a1=2, a2=3, a3=4, a4=5. Sum of smallest two = 5, a_n=5, so 5 <=5 holds (equality), so (1,2,4) gives degenerate triangle (2+3=5). That's violating. So condition holds. If sum > a_n, then for any k, a1+a2 > a_k (since a_k ≤ a_n). So then for any i<j<k, a_i+a_j >= a1+a2 > a_k >= a_k? Actually a_i+a_j ≥ a1+a2 > a_k, so a_i + a_j > a_k for all triples. That means all triples satisfy strict triangle inequality, so no violating triple. So indeed the condition is both necessary and sufficient.
Therefore, the problem is essentially: check if smallest two sum <= largest. If yes, output 1 2 n; else -1. That's O(1) per test case.
But wait, is there any subtlety about "non-degenerate triangle" requiring a_i + a_j > a_k (strict), and degenerate case when equality or less? The condition "impossible to construct a non-degenerate triangle" means that triangle with sides a_i, a_j, a_k either is degenerate (zero area) or impossible (cannot form triangle). In Euclidean geometry, triangle inequality requires sum of two sides > third. If equal, degenerate (collinear points) => area zero, not a non-degenerate triangle. So condition we need is a_i + a_j <= a_k. So equality qualifies as impossible to construct non-degenerate triangle. So our condition a1+a2 <= a_n works.
Thus solution is trivial.
But let's double-check with some edge cases: e.g., n=3, a=[1,2,3] => 1+2=3 <=3, so output 1 2 3. Indeed triangle 1,2,3 is degenerate (area zero). So correct.
n=3, a=[2,3,4] => 2+3=5>4, so output -1, meaning all triples? Only one triple (1,2,3) forms a triangle? Actually 2+3>4, yes non-degenerate. So -1.
n=4, a=[5,5,5,5] => 5+5=10>5, so -1? Wait 10>5, so condition false, output -1. But are there any triples that violate? For any three sides, 5+5>5, so they all form non-degenerate triangles (equilateral). So correct.
n=4, a=[1,100,101,200] => 1+100=101 <=200 true, output 1 2 4. Check triple: 1+100=101 <=200, violates. Also triple (2,3,4): 100+101=201>200, triangle; (1,3,4): 1+101=102<=200, also violates. So indeed existence.
What about a case where a1+a2 > a_n but there is some i,j not minimal such that a_i + a_j <= a_k? As argued, if a1+a2 > a_n, then for any k, a_k ≤ a_n < a1+a2 ≤ a_i+a_j? Since a_i+a_j ≥ a1+a2, so a_i+a_j > a_k. So no violating triple. So condition is necessary.
Thus solution is correct.
Given the problem is from Codeforces (likely problem "1095C?" Actually I recall problem "1366A Shovels and Swords"? Not that. There is problem "A. Triangle" or something? Actually there is a known problem: "A. Non-Decreasing? No it's "A. Bad Triangle". I recall a Codeforces problem: "Bad Triangle" (Ed. #657? Not sure). The solution is exactly to check the smallest two and largest. So yes.
But wait, there is nuance: The indices must be i<j<k. Our triple (1,2,n) satisfies that.
Thus implement.
But note that t up to 1000, sum n up to 1e5. So reading input accordingly.
Implementation details: Use 0-indexed but output 1-indexed.
Edge: n=3 always, so fine.
Now, double-check sample: They output 2 3 6 for first test case. Our output 1 2 7 also valid. So accepted.
Thus solution is trivial.
But maybe there is a catch: The problem statement says "it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k". And the condition is a_i + a_j <= a_k? Actually for triangle inequality, we need all three inequalities: a_i + a_j > a_k, a_i + a_k > a_j, a_j + a_k > a_i. Since we have sorted, only need to check smallest two sum > largest. So yes.
Therefore answer.
But wait, are we allowed to output any triple? Yes.
So implement.
Thus final code:
For each test case:
- read n
- read list a of length n
- if a[0] + a[1] <= a[-1]:
print(1, 2, n)
else:
print(-1)
But check if n may be 2? It's guaranteed n >=3. So fine.
That's it.
Now let's reflect if there's any hidden pitfall: Because a_i up to 1e9, sum fits in 64-bit integer. Use Python int.
Complexities: O(n) reading.
Edge: For multiple test cases, sum n up to 1e5, okay.
Thus solve.
But maybe there's a scenario where the two smallest are not the minimal sum? Because they are indices 1 and 2, but could there be a smaller sum from indices other than 1 and 2? No, because array sorted, the smallest two values are at positions 1 and 2. However, there might be duplicate values; but still the two smallest are at positions 1 and 2 (they might be equal). So sum is minimal.
Thus algorithm stands.
We can produce final answer.
We'll provide explanation in the final output.
Thus code.
But note: The problem might be tricky because some might think of more complex solution, but indeed it's that simple.
Will there be any test where a1 + a2 > a_n but there is some triple where a_i + a_j <= a_k because maybe the smallest two indices are not both less than k? For k=3, i and j must be 1 and 2, so a1+a2 <= a3 would be condition. If a1+a2 > a3, then that triple not violating. For larger k, indices include 1 and 2, so the minimal sum is still a1+a2. So if a1+a2 > a_k for all k, then all sums > a_k.
Thus correct.
I think this is final.
Now write the Python code.
Implementation:
def solve():
import sys
data = sys.stdin.read().split()
it = iter(data)
t = int(next(it))
out_lines = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
if a[0] + a[1] <= a[-1]:
out_lines.append(f"1 2 {n}")
else:
out_lines.append("-1")
sys.stdout.write("\n".join(out_lines))
That's all.
Test with sample.
Will run mentally:
t=3
n=7, a as given: 4+6=10 <=20 => "1 2 7"
n=4, 10+10=20 >11 => "-1"
n=3, 1+1=2 <=1e9 => "1 2 3"
Matches expected except first line "1 2 7" vs sample's "2 3 6", but any valid answer is accepted.
Thus solution.
I'll produce final answer with explanation.
```python
import sys
def solve() -> None:
data = sys.stdin.buffer.read().split()
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
if a[0] + a[1] <= a[-1]:
out.append(f"1 2 {n}")
else:
out.append("-1")
sys.stdout.write("\n".join(out))
if name == "main":
solve()