Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) if a[-1]<a[0]+a[1]: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
if __name__=="__main__": t=int(input()) while(t): t-=1 n=int(input()) li=list(map(int,input().split())) i=0 j=1 k=len(li)-1 flag=0 while(i<len(li)-2): while(j<len(li)-1): while(j<k): if li[i]+li[j]>li[k] and li[j]+li[k]>li[i] and li[k]+li[i]>li[j]: pass else: flag=1 print(i+1,j+1,k+1) break k-=1 j+=1 if flag==1: break i+=1 if flag==1: break if flag==0: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
ans = [] for t in range(int(input())): n = int(input()) A = list(map(int, input().split())) if A[0] + A[1] <= A[-1]: ans += [[1, 2, n]] else: ans += [[-1]] [print(*x) for x in ans]
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for i in range(int(input())): n = int(input()) ar = list(map(int,input().split())) if ar[0]+ar[1]>ar[-1]: print("-1") else: print("1","2",n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
T = int(input()) for _ in range(T): length = int(input()) a = list(map(int, input().split())) x = a[0] y = a[1] z = a[-1] if (x+y <= z): print(1, 2, len(a)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for p in range(int(input())): n=int(input()) x=[int(x) for x in input().split()] i,j,k=0,1,n-1 a,b,c=x[i],x[j],x[k] if (a+b)>c: print(-1) else: print(i+1,j+1,k+1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
z = (int(input())) for i in range(z): n = int(input()) arr = list(map(int,input().split())) if arr[0] + arr[1] <= arr[n-1]: print('1 2',n) else: print('-1')
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) b=list(map(int,input().split())) if (b[0]+b[1])<=b[-1]: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; public class P1 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); int numTests = reader.nextInt(); for (int testNum = 0; testNum < numTests; testNum++) { int length = reader.nextInt(); long first = Integer.MAX_VALUE, second = Integer.MAX_VALUE, last = Integer.MIN_VALUE, i = -1, j = -1, k = -1; for (int a = 1; a <= length; a++) { long curr = reader.nextLong(); if (curr < first) { second = first; j = i; first = curr; i = a; } else if (curr < second) { second = curr; j = a; } if (curr >= last) { last = curr; k = a; } } if (first == 0) { System.out.println(-1); } else if (first + second <= last) { System.out.println(i + " " + j + " " + k); } else { System.out.println(-1); } } reader.close(); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; public class solution{ private int t,n; private int[] A = new int[50005]; public void Process() { Scanner scanner = new Scanner(System.in); t = scanner.nextInt(); for (int ii = 1; ii <= t; ii++) { n = scanner.nextInt(); for (int i = 0; i < n; i++) { A[i] = scanner.nextInt(); } if (A[0] + A[1] <= A[n-1]) { System.out.println("1 2 "+n); } else System.out.println("-1"); } } public static void main(String args[]) { solution s = new solution(); s.Process(); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) l=[int(i) for i in input().split()] print(1,2,n) if l[0]+l[1]<=l[-1] else print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(0,t): n = int(input()) l = list(map(int,input().split())) a=l[0] c=l[n-1] b=False for i in range(1,n-1): if(a+l[i] <=c): b=i+1 break if(b): print("1", b, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): N=int(input()) A=list(map(int,input().split())) t=A[0]+A[1] temp=0 for i in range(2,N): if(A[i]>=t): temp=1 print(1,2,i+1) break if(temp==0): print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def isTriangle(a, b, c): if a+b <= c or a+c <= b or b+c <= a: return False return True t = int(input()) while t != 0: t -= 1 n = int(input()) arr = [int(x) for x in input().split()] if not isTriangle(arr[0], arr[1], arr[-1]): print ("1 2", n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) if l[0]+l[1]<=l[n-1]: print('1','2',n) else: print('-1')
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from collections import Counter import sys sys.setrecursionlimit(10 ** 6) mod = 1000000007 inf = int(1e18) dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] def inverse(a): return pow(a, -1, mod) def solve(): n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] <= a[-1]: print(1, 2, n) else: print(-1) def main(): t = int(input()) for _ in range(t): solve() main()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import os import heapq import sys import math import operator from collections import defaultdict from io import BytesIO, IOBase """def gcd(a,b): if b==0: return a else: return gcd(b,a%b)""" # def pw(a,b): # result=1 # while(b>0): # if(b%2==1): result*=a # a*=a # b//=2 # return result def inpt(): return [int(k) for k in input().split()] def main(): for _ in range(int(input())): n=int(input()) ar=inpt() k=n-1 if(ar[0]+ar[1]<=ar[k]): print(1,2,n) else: print(-1) BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") if __name__ == "__main__": main()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; import java.io.*; public class Mamo { static long mod=1000000007; static Reader in=new Reader(); static List<Integer >G[]; static long a[],p[],xp[],xv[]; static StringBuilder Sd=new StringBuilder(),Sl=new StringBuilder(); public static void main(String [] args) { //Dir by MohammedElkady int t=in.nextInt(); while(t-->0) { int n=in.nextInt(),p1=-1,p2=-1,p3=-1; int a[]=in.arr(n); if(a[0]+a[1]<=a[n-1]) { p1=1;p2=2;p3=n;} if(p1==-1) {out.append("-1\n");} else {out.append(p1+" "+p2+" "+p3+ " \n");} } out.close(); } static long ans=0L; static boolean v[]; static ArrayList<Integer>res; static Queue <Integer> pop; static Stack <Integer>rem; public static void Dfs(int o) { v[o]=true; for(int i:G[o]) { Dfs(i); if(a[i]>0) { res.add(i+1); a[o]+=a[i];} else { rem.add(i+1); } } ans+=a[o]; } public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static long gcd(long g,long x){if(x<1)return g;else return gcd(x,g%x);} static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int nextInt(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(s()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = nextInt();}return ret;} } } class node implements Comparable<node>{ int a, b; node(int tt,int ll){ a=tt;b=ll; } @Override public int compareTo(node o) { return b-o.b; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Sorting{ public static int[] bucketSort(int[] array, int bucketCount) { if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count"); if (array.length <= 1) return array; //trivially sorted int high = array[0]; int low = array[0]; for (int i = 1; i < array.length; i++) { //find the range of input elements if (array[i] > high) high = array[i]; if (array[i] < low) low = array[i]; } double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket ArrayList<Integer> buckets[] = new ArrayList[bucketCount]; for (int i = 0; i < bucketCount; i++) { //initialize buckets buckets[i] = new ArrayList(); } for (int i = 0; i < array.length; i++) { //partition the input array buckets[(int)((array[i] - low)/interval)].add(array[i]); } int pointer = 0; for (int i = 0; i < buckets.length; i++) { Collections.sort(buckets[i]); //mergeSort for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets array[pointer] = buckets[i].get(j); pointer++; } } return array; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) i = 0 while i < t: n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] <= a[len(a) - 1]: print(1, 2, len(a)) else: print(-1) i += 1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
test = int(input().strip()) for _ in range(test): n = int(input().strip()) arr = list(map(int, input().strip().split(" "))) i1, i2, i3 = 0, 1, n-1 if arr[i1] + arr[i2] <= arr[i3]: print(i1 + 1, i2 + 1, i3 + 1) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<int> ar[1000001]; int vis[1000001]; int freq1[26]; int freq2[26]; bool checkPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long long power(long long a, long long b) { if (b == 0) return 1; if (b == 1) return a; if (b % 2 == 1) return (power(a, b - 1) * a) % 1000000007; long long q = power(a, b / 2); return (q * q) % 1000000007; } bool CPT(long long n) { return !(n & (n - 1)); } long long gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(int a, int b) { return (a / gcd(a, b)) * b; } bool isSubsetSum(int set[], int n, int sum) { bool subset[n + 1][sum + 1]; for (int i = 0; i <= n; i++) subset[i][0] = true; for (int i = 1; i <= sum; i++) subset[0][i] = false; for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j < set[i - 1]) subset[i][j] = subset[i - 1][j]; if (j >= set[i - 1]) subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]]; } } return subset[n][sum]; } bool compare(string a, string b) { string ab = a + b; string ba = b + a; return ab > ba; } bool isSubSequence(string str1, string str2, int m, int n) { if (m == 0) return true; if (n == 0) return false; if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); return isSubSequence(str1, str2, m, n - 1); } bool areEqual(int arr1[], int arr2[], int n, int m) { if (n != m) return false; int b1 = arr1[0]; int b2 = arr2[0]; for (int i = 1; i < n; i++) { b1 ^= arr1[i]; } for (int i = 1; i < m; i++) { b2 ^= arr2[i]; } int all_xor = b1 ^ b2; if (all_xor == 0) return true; return false; } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int nextPrime(int N) { if (N <= 1) return 2; int prime = N; bool found = false; while (!found) { prime++; if (isPrime(prime)) found = true; } return prime; } void solve() { long long n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; if (v[0] + v[1] <= v[n - 1]) { cout << 1 << " " << 2 << " " << n << "\n"; return; } cout << -1 << "\n"; } int main() { int tt; cin >> tt; while (tt--) solve(); return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): l = int(input()) a = list(map(int, input().strip().split())) if l < 3: print(-1) continue if a[0]+a[1] <= a[l-1]: print("{0} {1} {2}".format(1, 2, l)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.*; import java.util.*; public class code { public static void check(int b[],int a) { for(int i=0;i<a-1;i++) { if(b[i]+b[i+1]<=b[a-1]) { System.out.println(i+1+" "+(i+2)+" "+a); return; } } System.out.println(-1); return; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b[]=new int[a]; for(int i=0;i<a;i++) { b[i]=sc.nextInt(); } check(b,a); } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin def readline(): return stdin.readline() tests = int(readline()) def solve(n, a): i = 0 j = 1 k = n - 1 if a[k] >= a[i] + a[j] or a[i] >= a[k] + a[j] or a[j] >= a[i] + a[k]: return str(i + 1) + ' ' + str(j + 1) + ' ' + str(k + 1) return -1 for t in range(0, tests): n = int(readline().rstrip("\n")) #n, d, m = list(map(int, readline().rstrip("\n").split(' '))) a = list(map(int, readline().rstrip("\n").split(' '))) print(solve(n, a))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a[100000]; cin >> t; for (int i = 0; i < t; i++) { cin >> n; for (int j = 0; j < n; j++) { cin >> a[j]; } if (a[0] + a[1] <= a[n - 1]) cout << 1 << ' ' << 2 << ' ' << n << endl; else cout << -1 << endl; } return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for _ in range(t): n=int(input()) ar=[int(i) for i in input().strip().split(" ")] a=ar[0] b=ar[1] c=ar[-1] if a+b>c: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) if lst[0]+lst[1]<=lst[-1]: print("1 2 " + str(n)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def solve(): n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] <= a[-1]: print(1, 2, n) return print(-1) for i in range(int(input())): solve()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys #input=sys.stdin.buffer.readline t=int(input()) while t: t-=1 n=int(input()) a=list(map(int,input().split())) k=a[0]+a[1] c=0 for i in range(2,n): if k<=a[i]: c=1 break if c==1: print(1,2,i+1) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) while t>0: t-=1 n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]<=a[-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
/*Shabeg Singh Gill*/ //code import java .util.Scanner ; import java.util.*; import java.io.*; import java.nio.IntBuffer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; //import java.io.OutputStreamReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.lang.Math; import java.io.InputStream; import java.util.InputMismatchException; import java.awt.Point; import java.util.HashMap; import java.util.Collections; import java.util.Arrays; //import java.util.Collections.reverseOrder() public class cf2{ public static int binarysearch(int[] arr,int num){ int n; n=arr.length; int ans; ans=0; int start; start=0; int end ; end=n-1; while(start<=end){ int mid; mid=(start+end)/2; if (arr[mid]>num){ end=mid-1; } else{ ans=mid+1; start=mid+1; } } return ans; } public static void merger(int startind,int midind,int endind, ArrayList<Integer> arr){ ArrayList<Integer> mergedSortedArray; mergedSortedArray= new ArrayList<Integer>(); int rightIndex ; rightIndex= midind+1; int leftIndex ; leftIndex= startind; while(midind>=leftIndex && endind>=rightIndex){ if(arr.get(leftIndex)<=arr.get(rightIndex)){ mergedSortedArray.add(arr.get(leftIndex)); leftIndex++; }else{ mergedSortedArray.add(arr.get(rightIndex)); rightIndex++; } } while(midind>=leftIndex){ mergedSortedArray.add(arr.get(leftIndex)); leftIndex++; } while(endind>=rightIndex){ mergedSortedArray.add(arr.get(rightIndex)); rightIndex++; } int i ; i= 0; int j ; j= startind; while(i<mergedSortedArray.size()){ arr.set(j, mergedSortedArray.get(i++)); j++; } } public static void divide(int startIndex,int endIndex, ArrayList<Integer> arr){ if(endIndex >startIndex&& (endIndex-startIndex)>=1){ int mid; mid = (endIndex + startIndex)/2; divide(startIndex, mid, arr); divide(mid+1, endIndex, arr); merger(startIndex,mid,endIndex,arr); } } public static int gcd1(int a, int b){ return fact(Math.min(a, b)); } public static long gcd2(long a, long b ){ if(b==0){ return a ; } else { return gcd2(b, a%b); } } public static int fact(int n){ int ans =1; for(int i =1; i<=n; i++){ ans=ans*i; } return ans ; } public static long lcm(long a, long b){ return (a*b)/gcd2(a, b); } public static int[] removeTheElement(int[] arr,int index){ if (arr == null || index < 0 || index >= arr.length) { return arr; } int[] anotherArray = new int[arr.length - 1]; for (int i = 0, k = 0; i < arr.length; i++) { if (i == index) { continue; } anotherArray[k++] = arr[i]; } return anotherArray; } public static long arrsum(int[]arr, int n ){ long sum =0; for(int i =0; i<n; i++){ sum=sum+arr[i]; } return sum ; } public static boolean isPrime(int n) { if (n%2==0){ return false; } for(int i=3;i<=Math.sqrt(n);i+=2) { if(n%i==0){ return false; } } return true; } public static int largest(int []arr,int n){ int max=Integer.MIN_VALUE; for(int x=0; x<n; x++){ if(arr[x]>max){ max=arr[x]; } } return max; //Arrays.sort(arr); //return arr[n - 1]; } public static void main(final String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); Scanner s =new Scanner(System.in); int t =in.nextInt(); for(int i=0; i<t; i++){ int n =in.nextInt(); int[] arr =new int[n]; for(int j =0; j<n; j++){ arr[j]=in.nextInt(); } //String ans=" "; int ans=0; int f1=0; int f2=0; int f3=0; for(int x =2; x<n; x++ ){ if((arr[0]+arr[1])<=arr[x]){ //ans="-1"; //ans=1+" "+ 2+" "+(x); ans=1; f1=1; f2=2; f3=x+1; break; } } if(ans==1){ System.out.println(f1+" "+f2+" "+f3); } else { System.out.println("-1"); } } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(final InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (final IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (final IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); final StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(final int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin,stdout from itertools import combinations from collections import defaultdict,Counter import math def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringListIn(): return([x for x in stdin.readline().split()]) def intIn(): return (int(stdin.readline())) def stringIn(): return (stdin.readline().strip()) if __name__=="__main__": t=intIn() while(t>0): t-=1 n=intIn() a=listIn() f=0 s=a[0]+a[1] for i in range(2,n): if s<=a[i]: f=1 break if f: print(1,2,i+1) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# begin FastIO import os inp=os.read(0,os.fstat(0).st_size).split(b"\n");_ii=-1 def rdln(): global _ii _ii+=1 return inp[_ii] inin=lambda typ=int: typ(rdln()) inar=lambda typ=int: [typ(x) for x in rdln().split()] inst=lambda: rdln().strip().decode() # end FastIO # begin DEBUG _DEBUG=0 def debug(*args): if _DEBUG: import inspect frame = inspect.currentframe() frame = inspect.getouterframes(frame)[1] string = inspect.getframeinfo(frame[0]).code_context[0].strip() arns = string[string.find('(') + 1:-1].split(',') print('.#debug:',end=' ') for i,j in zip(arns,args): print(i,' = ',j,end=', ') print() # end DEBUG _T_=inin() for _t_ in range(_T_): debug(_t_) n=inin() a=inar() if a[0]+a[1]>a[n-1]: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# def checkKey(dict, key): # if key in dict: # return True # return False # def helper(s): # l=len(s) # if (l==1): # l=[] # l.append(s) # return l # ch=s[0] # recresult=helper(s[1:]) # myresult=[] # myresult.append(ch) # for st in recresult: # myresult.append(st) # ts=ch+st # myresult.append(ts) # return myresult # mod=1000000000+7 # def helper(s,n,open,close,i): # if(i==2*n): # for i in s: # print(i,end='') # print() # return # if(open<n): # s[i]='(' # helper(s,n,open+1,close,i+1) # if(close<open): # s[i]=')' # helper(s,n,open,close+1,i+1) # def helper(arr,i,n): # if(i==n-1): # recresult=[arr[i]] # return recresult # digit=arr[i] # recresult=helper(arr,i+1,n) # myresult=[] # for i in recresult: # myresult.append(i) # myresult.append(i+digit); # myresult.append(digit) # return myresult # import copy # n=int(input()) # arr=list(map(int,input().split())) # ans=[] # def helper(arr,i,n): # if(i==n-1): # # for a in arr: # # print(a,end=" ") # # print() # l=copy.deepcopy(arr) # ans.append(l) # return # for j in range(i,n): # if(i!=j): # if(arr[i]==arr[j]): # continue # else: # arr[i],arr[j]=arr[j],arr[i] # helper(arr,i+1,n) # arr[j],arr[i]=arr[i],arr[j] # else: # arr[i],arr[j]=arr[j],arr[i] # helper(arr,i+1,n) # def helper(sol,n,m): # for i in range(n+1): # for j in range(m+1): # print(sol[i][j],end=" ") # print() # def rat_in_a_maze(maze,sol,i,j,n,m): # if(i==n and j==m): # sol[i][j]=1 # helper(sol,n,m) # return True # if(i>n or j>m): # return False # if(maze[i][j]=='X'): # sol[i][j]=0 # return False # sol[i][j]=1 # if(rat_in_a_maze(maze,sol,i,j+1,n,m)): # sol[i][j]=0 # return True # elif(rat_in_a_maze(maze,sol,i+1,j,n,m)): # sol[i][j]=0 # return True # else: # sol[i][j]=0 # return False # n,m=map(int,input().split()) # l=[] # sol=[[0]*m]*n # for i in range(n): # arr=list(input()) # l.append(arr) # rat_in_a_maze(l,sol,0,0,n-1,m-1) test=int(input()) for _t in range(test): n=int(input()) arr=list(map(int , input().split())) if ((arr[0]+arr[1])<=arr[-1]): print(1,end=" ") print(2,end=" ") print(n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; if (a[1] + a[2] <= a[n]) { cout << "1" << " " << "2" << " " << n << endl; } else cout << "-1" << endl; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for u in range(int(input())): n = int(input()) x = [int(w) for w in input().split()] if x[0] + x[1] > x[-1]: print(-1) else: print(1, 2, n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int oo = INT_MAX; int t, n; int a[N]; int main() { cin >> t; while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); if (a[0] + a[1] <= a[n - 1]) printf("%d %d %d\n", 1, 2, n); else puts("-1"); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) cnt = 0 while (cnt < t): cnt += 1 n = int(input()) flag = False a = [int(i) for i in input().split()] if a[0] + a[1] <= a[n - 1]: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for t in range(int(input())): n = int(input()) li = [int(x) for x in input().split()] if li[0]+li[1]<=li[-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (a[0] + a[1] <= a[n - 1]) { cout << "1 2 " << n << endl; } else cout << -1 << endl; } return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import math t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]<=a[-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, t, n; cin >> t; while (t--) { cin >> n; int arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } if ((arr[0] + arr[1] <= arr[n - 1]) || (arr[1] + arr[n - 1] <= arr[0]) || (arr[0] + arr[n - 1] <= arr[1])) { cout << "1" << " " << "2" << " " << n << endl; } else { cout << "-1" << endl; } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) a = [int(i) for i in input().split()] if a[0] + a[1] > a[-1]: print(-1) else: print("1 2", n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for i in range(int(input())): n = int(input()) array = list(map(int, input().split())) if(array[0] + array[1] <= array[-1]): print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for i in [0]*int(input()): n = int(input()) l = list(map(int, input().split(' '))) if l[0] + l[1] <= l[-1]: print('1 2', n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin for _ in range(int(stdin.readline())): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) if a[0] + a[1] <= a[-1]: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int s[50001]; signed main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); for (int i = 0; i < (n); i++) { scanf("%d", &s[i]); } for (int i = 1; i < n - 1; i++) { if (s[0] + s[i] <= s[n - 1]) { printf("%d %d %d\n", 1, i + 1, n); goto hell; } } printf("-1\n"); hell : {} } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for i in range(t): n = int(input()) a = [int(s) for s in input().split()] sum = a[0] + a[1] flag = 0 j = 2 while(flag == 0): if(sum <= a[j]): print(1, 2, j+1) flag = 1 if(j == n-1 and flag == 0): print(-1) flag = 1 j += 1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for x in range(t): n = int(input()) a = list(map(int, input().split())) b = list(a) max1 = max(a) a.remove(max1) min1 = min(a) a.remove(min1) min2 = min(a) a.remove(min2) if (max1 >= (min1 + min2)): print(1, 2, len(b)) continue a = b max1 = max(a) a.remove(max1) min1 = min(a) a.remove(min1) max2 = max(a) a.remove(min2) if max1 >= (max2 + min1): print(1, len(b) - 1, len(b)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) num = list(map(int, input().split())) if num[0] + num[1] > num[n-1]: print("-1") else: print("{} {} {}".format(1, 2, n))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) a=l[0] b=l[1] c=l[len(l)-1] if (a+b>c and b+c>a and c+a>b)==False: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int a[50005]; int main() { int t, n; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (a[1] + a[2] <= a[n]) { printf("1 2 %d\n", n); } else { puts("-1"); } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys from collections import defaultdict as dd from collections import deque from functools import * from fractions import Fraction as f from copy import * from bisect import * from heapq import * from math import * from itertools import permutations def eprint(*args): print(*args, file=sys.stderr) zz=1 #sys.setrecursionlimit(10**6) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') def inc(d,c): d[c]=d[c]+1 if c in d else 1 def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def comp(a,b): if(a>b): return 2 return 2 if a==b else 0 def gi(): return [xx for xx in input().split()] def fi(): return int(input()) def pro(a): return reduce(lambda a,b:a*b,a) def swap(a,i,j): a[i],a[j]=a[j],a[i] def si(): return list(input().rstrip()) def mi(): return map(int,input().split()) def gh(): sys.stdout.flush() def isvalid(i,j): return 0<=i<n and 0<=j<n def graph(n,m): for i in range(m): x,y=mi() a[x].append(y) a[y].append(x) t=fi() while t>0: t-=1 n=fi() a=li() if a[0]+a[1]<=a[n-1] : print(1,2,n ) else : print(-1 )
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
test=int(input()) for t in range(test): n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]>a[n-1]: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') import math import collections from sys import stdin,stdout,setrecursionlimit import bisect as bs setrecursionlimit(2**20) M = 10**9+7 T = int(stdin.readline()) # T = 1 for _ in range(T): n = int(stdin.readline()) # n,d,m = list(map(int,stdin.readline().split())) a = list(map(int,stdin.readline().split())) # q = int(stdin.readline()) # a = list(map(int,stdin.readline().split())) # b = list(map(int,stdin.readline().split())) b = [] for i in range(n): b.append((a[i],i+1)) b.sort() if(b[-1][0] >= b[0][0]+b[1][0]): fin = [b[-1][1], b[0][1], b[1][1]] fin.sort() for h in fin: print(h,end=' ') print('') else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin,stdout for _ in range(int(stdin.readline())): n=int(stdin.readline()) # =map(int,stdin.readline().split()) a=list(map(int,stdin.readline().split())) x=a[0];y=a[1];z=a[-1] if x+y>z and y+z>x and x+z>y: print(-1) continue print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) while t: t-=1 n = int(input()) l = list(map(int, input().split())) if l[0]+l[1]<=l[-1]: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class BadTriangle { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(bf.readLine()); for (int i = 0; i < test; i++) { int n = Integer.parseInt(bf.readLine()); StringTokenizer st = new StringTokenizer(bf.readLine()); long arr[]= new long[n]; for (int j = 0; j < n; j++) { arr[j]=Integer.parseInt(st.nextToken()); } if (arr[0]+arr[1]<=arr[n-1]) System.out.println("1 2 "+n); else System.out.println(-1); } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
T = int(input()) for _ in range(T): input() l = list(map(int,input().split())) for i in range(len(l)): l[i] = (l[i], i) l.sort() if l[0][0] + l[1][0] <= l[-1][0]: print(l[0][1] + 1, l[1][1] + 1, l[-1][1] + 1) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
a=int(input()) for i in range(0,a): b=int(input()) arr=list(map(int,input().split())) if(arr[0]+arr[1]>arr[len(arr)-1]): print(-1) else: print(1,2,len(arr))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for castle in range(t): n=int(input()) ls=list(map(int,input().split())) a,b,c=ls[0],ls[1],ls[-1] if a+b>c: print(-1) else: print(*[1,2,n])
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; public class Main { static void rev(int []a) { int i=0,j=a.length-1; while(i<j) { int t=a[i]; a[i]=a[j]; a[j]=t; i++;j--; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while(T-->0) { int N=sc.nextInt(); int[]a=new int[N]; for(int i=0;i<N;i++) a[i]=sc.nextInt(); if(a[0]+a[1]<=a[N-1]) System.out.println(1+" "+2+" "+N); else System.out.println(-1); } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for s in[*open(0)][2::2]: x,y,*a,z=map(int,s.split()) print(*([1,2,len(a)+3],[-1])[x+y>z])
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def main(): t = int(input()) for case in range(t): n = int(input()) A = [int(x) for x in input().split()] flag = False for i in range(n-2): last = n-1 for rt in range(n-i-2): last = n-1 - rt if(A[i] + A[i+1] > A[last]): break else: print(i+1, i+2, last+1) flag = True break if(flag): break if(not flag): print(-1) """ flag = False for a in range(n): for b in range(a+1,n): lhs = A[a]+A[b] for c in range(b+1,n): if(lhs <= A[c]): print(a+1, b+1, c+1) flag = True break if(flag): break if(flag): break if(not flag): print(-1) """ if __name__ == '__main__': main()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; import java.io.*; public class Task{ // taking inputs static BufferedReader s1; static BufferedWriter out; static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;} static int int_v (String s1){return Integer.parseInt(s1);} static long long_v(String s1){return Long.parseLong(s1);} static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;} static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;} static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));} static long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);} static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;} static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;} static long ModInv(long a,long m){return Modpow(a,m-2,m);} static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);} //sort map w.r.t value use-> TreeSet of array? write comparator which depends on all the entries of array otherwise weired behavior you can prove it. //......................................@uthor_Alx.............................................. // vikassingh@maths.iitd.ac.in //Hod.Career.Services@admin.iitd.ac.in //careerservices.iitd@gmail.com //placement@admin.iitd.ac.in static long[] f; public static void main(String[] args) throws IOException{ assign(); int t=int_v(read()),cn=1; while(t--!=0){ int n=int_v(read()); int[] a=int_arr(); int res=-1;boolean b=false; if((a[0]+a[1])<=a[n-1]){ out.write((1)+" "+(2)+" "+(n)+"\n"); } else{ out.write("-1\n"); } } out.flush(); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
case=int(input()) while case!=0: n=int(input()) a=list(map(int,input().split())) chk=False i=0 for i in range(n-2): if a[i]+a[i+1]<=a[n-1]: print("1","2",n) chk=True break if chk==False: print("-1") case-=1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
## necessary imports import sys input = sys.stdin.readline from bisect import bisect_left; from bisect import bisect_right; from math import ceil, factorial; def ceil(x): if x != int(x): x = int(x) + 1; return x; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp; ## gcd function def gcd(a,b): if b == 0: return a; return gcd(b, a % b); ## nCr function efficient using Binomial Cofficient def nCr(n, k): if(k > n - k): k = n - k; res = 1; for i in range(k): res = res * (n - i); res = res / (i + 1); return int(res); ## prime factorization def primefs(n): ## if n == 1 ## calculating primes primes = {} while(n%2 == 0 and n > 0): primes[2] = primes.get(2, 0) + 1 n = n//2 for i in range(3, int(n**0.5)+2, 2): while(n%i == 0 and n > 0): primes[i] = primes.get(i, 0) + 1 n = n//i if n > 2: primes[n] = primes.get(n, 0) + 1 ## prime factoriazation of n is stored in dictionary ## primes and can be accesed. O(sqrt n) return primes ## MODULAR EXPONENTIATION FUNCTION def power(x, y, p): res = 1 x = x % p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : res = (res * x) % p y = y >> 1 x = (x * x) % p return res ## DISJOINT SET UNINON FUNCTIONS def swap(a,b): temp = a a = b b = temp return a,b; # find function with path compression included (recursive) # def find(x, link): # if link[x] == x: # return x # link[x] = find(link[x], link); # return link[x]; # find function with path compression (ITERATIVE) def find(x, link): p = x; while( p != link[p]): p = link[p]; while( x != p): nex = link[x]; link[x] = p; x = nex; return p; # the union function which makes union(x,y) # of two nodes x and y def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x,y = swap(x,y) if x != y: size[x] += size[y] link[y] = x ## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #### PRIME FACTORIZATION IN O(log n) using Sieve #### MAXN = int(1e5 + 5) def spf_sieve(): spf[1] = 1; for i in range(2, MAXN): spf[i] = i; for i in range(4, MAXN, 2): spf[i] = 2; for i in range(3, ceil(MAXN ** 0.5), 2): if spf[i] == i: for j in range(i*i, MAXN, i): if spf[j] == j: spf[j] = i; ## function for storing smallest prime factors (spf) in the array ################## un-comment below 2 lines when using factorization ################# # spf = [0 for i in range(MAXN)] # spf_sieve(); def factoriazation(x): ret = {}; while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1; x = x//spf[x] return ret; ## this function is useful for multiple queries only, o/w use ## primefs function above. complexity O(log n) ## taking integer array input def int_array(): return list(map(int, input().strip().split())); def float_array(): return list(map(float, input().strip().split())); ## taking string array input def str_array(): return input().strip().split(); #defining a couple constants MOD = int(1e9)+7; CMOD = 998244353; INF = float('inf'); NINF = -float('inf'); ################### ---------------- TEMPLATE ENDS HERE ---------------- ################### for _ in range(int(input())): n = int(input()); a = int_array(); if a[0] + a[1] <= a[-1]: print(*[1, 2, n]); else: print(-1);
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin input = lambda : stdin.readline().strip() for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) r = range(1,n+1) a.insert(0,n-1) ans = False x = a[1] y = a[2] for k in range(2,n+1): if(x+y<=a[k]): print(1,2,k) ans = True break if(not ans): print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int tc = 1; tc <= t; tc++) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int i = 0, j = 1, k = n - 1; if (v[i] + v[j] > v[k]) cout << -1 << endl; else { cout << i + 1 << " " << j + 1 << " " << k + 1 << endl; } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int p = 0; p < t; p++) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int flag = 0; int ans[3]; for (int i = 0; i < n - 2; i++) { int temp; temp = a[i] + a[i + 1]; if (temp <= a[n - 1]) { flag = 1; ans[0] = i + 1; ans[1] = i + 2; ans[2] = n; } if (flag == 1) break; } if (flag == 1) cout << ans[0] << " " << ans[1] << " " << ans[2] << endl; else cout << "-1" << endl; } return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) flag=0 for i in range(n-1): x=a[i] y=a[i+1] if(a[-1]>=x+y): x=i+1 y=i+2 flag=1 break if(flag==1): print(x,y,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for count in range(t): n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]>a[n-1]: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for i in range(t): n = int(input()) a = [int(x) for x in input().split()] if a[0]+a[1] > a[n-1]: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; mt19937 gen(time(0)); void setIO(string name = "") { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { setIO(); int t, n, x; cin >> t; for (int j = 0; j < t; j++) { cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (a[n - 1] >= a[0] + a[1]) { cout << "1 2 " << n << "\n"; } else { cout << "-1\n"; } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input("")) for i in range(t): n = int(input("")) arr = input().split(" ") if int(arr[0])+int(arr[1])<=int(arr[-1]): print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
test_cases = int(input()) for tests in range(0, test_cases): n = int(input()) l = list(map(int, input().split())) if l[0] + l[1] <= l[n - 1]: print(f"1 2 {n}") else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.*; import java.math.*; import java.util.*; public class Main { static final int INF = (int) (1e9 + 10); static final int MOD = (int) (1e9 + 7); static final int N = (int) (4e5 + 5); // static ArrayList<Integer>[] graph; // static boolean visited[]; // static long size[]; public static void main(String[] args) throws NumberFormatException, IOException { FastReader sc = new FastReader(); PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // Scanner scn = new Scanner(System.in); // int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int arr[] = sc.nextIntArray(n); if (arr[0] + arr[1] > arr[n - 1]) { pr.println("-1"); } else pr.println(1 + " " + 2 + " " +(n) ); } // // Coded to Perfection by Rohan Mukhija pr.flush(); pr.close(); } /* * Template From Here */ static class Pair implements Comparable<Pair> { int u; int v; Pair(int u, int v) { this.u = u; this.v = v; } public int compareTo(Pair compareEdge) { return Long.compare(this.v, compareEdge.v); } }; private static boolean possible(long[] arr, double mid, long k) { long c = 0; for (int i = 0; i < arr.length; i++) { c += ((arr[i]) / mid); if (c % arr[i] == 0) c--; } // System.out.println(mid+" "+c+" "+k); if (c <= k) return true; return false; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static int lowerBound(ArrayList<Integer> array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value <= array.get(mid)) { high = mid; } else { low = mid + 1; } } return low; } public static long mul(long a, long b) { return (a * b) % MOD; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void sortbyColumn(int[][] att, int col) { // Using built-in sort function Arrays.sort Arrays.sort(att, new Comparator<int[]>() { @Override // Compare values according to columns public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator // if (entry1[col] > entry2[col]) // return 1; // else //(entry1[col] >= entry2[col]) // return -1; return new Integer(entry1[col]).compareTo(entry2[col]); // return entry1[col]. } }); // End of function call sort(). } public static void sortbyColumn(double[][] att, int col) { // Using built-in sort function Arrays.sort Arrays.sort(att, new Comparator<double[]>() { @Override // Compare values according to columns public int compare(final double[] entry1, final double[] entry2) { // To sort in descending order revert // the '>' Operator // if (entry1[col] > entry2[col]) // return 1; // else //(entry1[col] >= entry2[col]) // return -1; return new Double(entry1[col]).compareTo(entry2[col]); // return entry1[col]. } }); // End of function call sort(). } static class pair { int V, I; pair(int v, int i) { V = v; I = i; } } public static int[] swap(int data[], int left, int right) { int temp = data[left]; data[left] = data[right]; data[right] = temp; return data; } public static int[] reverse(int data[], int left, int right) { while (left < right) { int temp = data[left]; data[left++] = data[right]; data[right--] = temp; } return data; } public static boolean findNextPermutation(int data[]) { if (data.length <= 1) return false; int last = data.length - 2; while (last >= 0) { if (data[last] < data[last + 1]) { break; } last--; } if (last < 0) return false; int nextGreater = data.length - 1; for (int i = data.length - 1; i > last; i--) { if (data[i] > data[last]) { nextGreater = i; break; } } data = swap(data, nextGreater, last); data = reverse(data, last + 1, data.length - 1); return true; } static long ncr(long a, long b) { if (b > a - b) return ncr(a, a - b); long ansMul = 1; long ansDiv = 1; for (int i = 0; i < b; i++) { ansMul *= (a - i); ansDiv *= (i + 1); ansMul %= MOD; ansDiv %= MOD; } long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD; return ans; } static long __gcd(long n1, long n2) { long gcd = 1; for (int i = 1; i <= n1 && i <= n2; ++i) { // Checks if i is factor of both integers if (n1 % i == 0 && n2 % i == 0) { gcd = i; } } return gcd; } static long power(long prev, long n2, long mod2) { long res = 1; prev = prev % mod2; if (prev == 0) return 0; while (n2 > 0) { if ((n2 & 1) == 1) res = (res * prev) % mod2; n2 = n2 >> 1; prev = (prev * prev) % mod2; } return res; } static long modInverse(long fac2, int p) { return power(fac2, p - 2, p); } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static BigInteger lcmm(String a, String b) { BigInteger s = new BigInteger(a); BigInteger s1 = new BigInteger(b); BigInteger mul = s.multiply(s1); BigInteger gcd = s.gcd(s1); BigInteger lcm = mul.divide(gcd); return lcm; } /* * static boolean prime[] = new boolean[10000007]; static int spf[] = new * int[10000007]; * * public static void sieveOfEratosthenes(int n) { for (int i = 2; i < n; * i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { * * if (prime[p] == true) { * * for (int i = p * p; i <= n; i += p) { prime[i] = false; spf[i] = p; } } } * } */ }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.*; import java.math.*; import java.util.*; public class A { public static void main(String[] agrs) { FastScanner sc = new FastScanner(); int yo = sc.nextInt(); while(yo-->0) { int n = sc.nextInt(); long[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = sc.nextLong(); } boolean is = false; for(int i = 2; i < n; i++) { if(a[i] >= a[0] + a[1]) { System.out.println(1 + " " + 2 + " " + (i+1)); is = true; break; } } if(!is) { System.out.println(-1); } } } static int mod = 1000000007; static long pow(int a, int b) { if(b == 0) { return 1; } if(b == 1) { return a; } if(b%2 == 0) { long ans = pow(a,b/2); return ans*ans; } else { long ans = pow(a,(b-1)/2); return a * ans * ans; } } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) if(a[0]+a[1]<=a[-1]): print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; int t; cin >> t; while (t--) { int n; cin >> n; vector<long long> a(n + 3); for (int i = 0; i < (int)(n); i++) cin >> a[i]; if (a[0] + a[1] <= a[n - 1]) cout << 1 << " " << 2 << " " << n << "\n"; else cout << -1 << "\n"; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): n=int(input()) list1=[int(x) for x in input().split()] val1=list1[0]+list1[1] if val1<=list1[n-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys max_int = 1000000001 # 10^9+1 min_int = -max_int t = int(input()) for _t in range(t): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) if a[0] + a[1] <= a[-1]: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) while t > 0: n = int(input()) x = list(map(int, input().split())) arr = list() arr2 = list() a = 0 arr = sorted(x) for i in range(3, n+1): if arr[i-1] >= (arr[0] + arr[1]): print(1, 2, i) a = a + 1 break if a == 0: print(-1) t = t - 1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# cook your dish here for x in range(int(input())): n=int(input()) a=[int(x) for x in input().split()][:n] c=a[0]+a[1] d=0 for x in range(2,n): if(c<=a[x] and n>=3): print('1 2',x+1) d=1 break if(d==0): print('-1')
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# cook your dish here def compute_lcm(num1, num2): if(num1>num2): num = num1 den = num2 else: num = num2 den = num1 rem = num % den while(rem != 0): num = den den = rem rem = num % den gcd = den lcm = int(int(num1 * num2)/int(gcd)) return lcm t = int(input()) import math import collections for i in range(t): n = int(input()) a = list(map(int,input().split())) s = a[0]+a[1] for i in range(2,n): if s>a[i]: continue else: print(1,2,i+1) break else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): n = int(input()) x = list(map(int, input().split())) a = x[0] b = x[1] c = x[n-1] if a+b <= c: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# -*- coding: utf-8 -*- """ Created on Fri Aug 14 20:10:59 2020 @author: Utkarsh """ n=int(input('')) a=[] while n>0: l=int(input('')) a=list(map(int, input().split(' ')[:l])) for i in range(0,l): if a[i]+a[i+1]<=a[l-i-1]: print( i+1, i+2,l-i) break else: print(-1) break n-=1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def sol(inp, n): sm = [] ind = [] po = 0 for i in range(n): sm.append(inp[i]) ind.append(i+1) po += 1 if po==2 and sum(sm) <= inp[-1]: print(*ind, end=" ") print(n) return if sum(sm)>inp[-1]: sm = [] ind = [] po = 0 continue print(-1) return if __name__ == '__main__': for _ in range(int(input())): n = int(input()) inp = list(map(int, input().split())) sol(inp, n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) if (l[0]+l[1])<=l[n-1]: print('1 2 '+str(n)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys from collections import Counter from math import ceil,gcd,log from bisect import bisect ,bisect_left,bisect_right input = sys.stdin.readline def check(a, b, c): if (a + b <= c) or (a + c <= b) or (b + c <= a) : return False else: return True def solve(n,arr): a = arr[0] b = arr[1] p = arr.index(a) q = arr.index(b) flag =False arr = arr[2:] for j,i in enumerate(arr): c = i if (not check(a,b,c)): ans = (a,b,j) flag = True break else: continue if(flag): if(p==q): q+=1 print(p+1,q+1,3+ans[-1]) else: print(-1) return def main(): for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) solve(n,arr) return if __name__ == '__main__': main()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) #print("out") for _ in range(t): n = int(input()) a = list(map(int,input().split())) i = 0 k = n-1 f = False while i+1<n and i+1<k: j = i+1 while j<k and a[i]+a[j]>a[k]: k-=1 if j<k and (not a[i]+a[j]>a[k]): print(i+1,j+1,k+1) break i+=1 else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def solution(arr): a,b,c = arr[0] , arr[1] ,arr[-1] if a + b > c : return -1 return 1 for _ in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] ans = solution(arr) if ans == -1 : print(-1) else: print(ans,ans+1,len(arr))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.Scanner; public class Main{ public static void main(String args[]) { Scanner s = new Scanner(System.in); int itr = s.nextInt(); int n,j; int arr[]; for(int i=0;i<itr;i++) { n=s.nextInt(); arr=new int[n]; for(j=0;j<n;j++) { arr[j]=s.nextInt(); } for(j=0;j<n-2;j++) { if( (arr[j]+arr[j+1]) > arr[n-1] ) { continue; } else { System.out.println( (j+1)+" "+(j+2)+" "+ (n) ); break; } } if(j==n-2) { System.out.println(-1); } } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class er93a { public static void main(String[] args) { FastScanner scan=new FastScanner(); int t=scan.nextInt(); for(int tt=0;tt<t;tt++) { int n=scan.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=scan.nextInt(); if(a[0]+a[1]<=a[n-1]) { System.out.println(1+" "+2+" "+n); } else System.out.println(-1); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; if(st.hasMoreTokens()) line = st.nextToken(); else try {return br.readLine();}catch(IOException e){e.printStackTrace();} while(st.hasMoreTokens()) line += " "+st.nextToken(); return line; } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; void test() { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; if (a[n - 1] >= a[0] + a[1]) cout << 1 << " " << 2 << " " << n << endl; else cout << -1 << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long t = 1; cin >> t; while (t--) { test(); } return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if a[i]+a[j]>a[k] and a[i]+a[k]>a[j] and a[j]+a[k]>a[i]: c=1 continue else: c=0 print("{} {} {}".format(i+1,j+1,k+1)) break break break break if c==1: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
from sys import stdin,stdout import bisect n=int(stdin.readline()) for i in range(n): ans=0 a=int(stdin.readline()) x=[int(i) for i in stdin.readline().split()] x.sort() if x[0]+x[1]>x[-1]: stdout.write('-1'+'\n') continue stdout.write(str(1)+' '+str(2)+' '+str(len(x))+'\n')
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) while t: n = int(input()) arr = list(map(int, input().split())) if arr[0] + arr[1] <= arr[-1]: print(1, 2, n) else: print(-1) t -= 1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import copy def get_output(array,length): max=array[-1] i=0 while(i!=length-2): sum=array[i]+array[i+1] if sum<=max: return i+1,i+2,length else: i+=1 return -1 test_cases=int(input()) for i in range(test_cases): length=int(input()) array=[int(i) for i in input().split()] res=get_output(array,length) if res!=-1: for i in res: print(i,end=" ") print() else: print(res)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys input = sys.stdin.readline T = int(input()) for testcase in range(T): n = int(input()) a = list(map(int,input().split())) if a[0] + a[1] > a[-1]: print(-1) else: print(1,2,n)