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
def Solution(arr): if not arr[0] + arr[1] > arr[-1]: return str(1) + ' ' + str(2) + ' ' + str(len(arr)) else: return -1 t = int(input()) for _ in range(t): __ = input() arr = list(map(int, input().split(' '))) print(Solution(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
# fin = open("a.in", "r") # buf = fin.read() # fin.close() import sys buf = sys.stdin.read() nowbuf = 0 endbuf = len(buf) def getint(): global nowbuf valnow = 0 while buf[nowbuf] < '0' or buf[nowbuf] > '9': nowbuf += 1 while nowbuf < endbuf and buf[nowbuf] >= '0' and buf[nowbuf] <= '9': valnow = valnow * 10 + int(buf[nowbuf]) nowbuf += 1 return valnow def solve(n): a = [] for i in range(0, n): a.append(getint()) if a[0] + a[1] <= a[n - 1]: print("1 2", n) else: print("-1") return t = getint() for i in range(0, t): solve(getint())
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, math, heapq, collections, itertools, bisect sys.setrecursionlimit(101000) def solve(n, a): l1, l2, l3 = a[0], a[1], a[n-1] if l1+l2 <= l3: return 1, 2, n return None, None, None t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) i, j, k = solve(n, a) if i is None: print(-1) else: print(i, j, k)
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()) A=list(map(int,input().split())) if A[0]+A[1]<=A[n-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
cpp
#include <bits/stdc++.h> using namespace std; struct solution { int t, n{0}; vector<int> a{}; void get_data() { cin >> t; } void solve() { while (t--) { cin >> n; a.clear(); a.resize(n); for (auto &el : a) cin >> el; auto f = a[0]; auto s = a[1]; bool printed = false; for (auto i = 2; i < a.size(); ++i) { if ((f + s) <= a[i]) { cout << 1 << " " << 2 << " " << i + 1 << "\n"; printed = true; break; } } if (!printed) cout << "-1\n"; } } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); solution s; s.get_data(); s.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
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class badTriangle { 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 static void main(String[] args) { FastReader sc = new FastReader(); 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[n-1]>=a[0]+a[1]) { System.out.print("1 2 "+(n)); System.out.println(); } 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 _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) p = (arr[0]+arr[1]+arr[n-1])/2 if p > arr[0] and p > arr[1] and p > arr[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 tt 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
for t in range(int(input())): n=int(input()) l=list(map(int,input().split())) c=l[n-1] b=l[1] a=l[0] if a+b<=c or b+c<=a or c+a<=b: 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 _ in range(t): q = int(input()) l = list(map(int, input().split())) if l[0]+l[1] > l[-1]: print(-1) else: print(1, 2, q)
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; void solve() { long long n, i, x; cin >> n; vector<long long> ar; for (i = 0; i < n; i++) { cin >> x; ar.push_back(x); } if ((ar[0] + ar[1]) <= ar[n - 1]) { cout << 1 << " " << 2 << " " << n << endl; } else { cout << -1 << endl; } } int main() { int t; cin >> t; while (t--) { 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
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x 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
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class CodeForces93 { public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(); PrintWriter pw = new PrintWriter(System.out); //long startTime = System.nanoTime(); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int len = sc.nextInt(); int[] arr = new int[len]; for (int j = 0; j < len; j++) { arr[j] = sc.nextInt(); } int max = arr[len-1]; int min = arr[0]; int min2 = arr[1]; if (min + min2 > max) { pw.println("-1"); } else { pw.println(1 + " " + 2 + " " + len); } } //long elapsedTime = System.nanoTime() - startTime; //pw.println(elapsedTime/1000000); pw.close(); } 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
for _ in range(int(input())): n= int(input()) li= list(map(int, input().strip().split())) if(li[0]+li[1]>li[-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 #another one inp=sys.stdin.buffer.readline inin=lambda typ=int: typ(inp()) inar=lambda typ=int: [typ(x) for x in inp().split()] inst=lambda : inp().decode().strip() _T_=inin() for _t_ in range(_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
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) if l[0]+l[1] > l[-1]: print(-1) else: print(1, 2, len(l))
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=[int(x) for x in input().split()] h=l[0]+l[1] count=0 for i in range(2,n): if(l[i]>=h): count=1 print("1 2",i+1) break if(count==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
# -*- coding: utf-8 -*- """ Created on Tue Aug 18 00:52:21 2020 @author: RACHIT """ def triplet(arr:list): if len(arr)==0: return [-1] if len(arr)==3: if arr[-1]>=arr[0]+arr[1]: return[1,2,3] return [-1] for i in range(len(arr)-1,2,-1): if arr[i]>arr[0]+arr[1]: return [1,2,i+1] return [-1] if __name__=="__main__": t=int(input()) while(t>0): x=int(input()) arr=[int(i) for i in input().split()] ans=triplet(arr) for j in ans: print(j,end=' ') print() t-=1 ''' 4 6 11 11 15 18 20 10 10 10 11 1 1 100000'''
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() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; long long int arr[n]; for (int j = 0; j < n; j++) { cin >> arr[j]; } if (arr[0] + arr[1] <= arr[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
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if a[0]<=a[-1]-a[1]: print(1,2,n) elif a[-1]>=a[0]+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
for _ in range(int(input())): n=int(input()) k=list(map(int,input().split())) if (k[0]+k[1]<=k[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
def fun(ls,n): prv=ls[0] prv_index=0 for i,val in enumerate(ls[1:-1]): i=i+1 nxt_index=i+1 nxt=ls[nxt_index] if(prv+val<=nxt): print(prv_index+1,i+1,nxt_index+1) return prv=val prv_index=i if(ls[0]+ls[1]<=ls[-1]): print(1,2,n) return print(-1) T = int(input()) for i in range(T): # var=input() val=int(input()) # st=input() # ms= list(map(int, input().split())) # ls= list(map(int, input().split())) st= list(map(int, input().split())) # fun(ls) fun(st,val)
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 bad_triangle(arr,n): s=arr[0]+arr[1] if s<=arr[n-1]: print(1,2,n) else: print(-1) t=int(input()) for i in range(t): n=int(input()) li=[int(x) for x in input().split()] bad_triangle(li,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 b=int(input()) a=input().split(" ") if int(a[0])+int(a[1])>int(a[-1]): print(-1) else: print(1,2,b)
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()) a=[] b=[] for i in range(t): a.append([]) b.append(int(input())) a[i]=[int(a[i]) for a[i] in input().split()] if(a[i][0]+a[i][1]>a[i][b[i]-1]): print('-1') else: print('1 2',end=' ') print(b[i])
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=[int(x) for x in input().split()] x=arr[0]+arr[1] flag=False for i in range(2,n): if arr[i]>=x: flag=True print(1,2,i+1) break if flag==False: 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 = input() t = int(t) def solve(n, arr): a1 = arr[0] a2 = arr[1] for i in range(2, n): if a1+a2<=arr[i]: print(1, 2, i+1) return print(-1) return for i in range(t): n = input() n = int(n) arr = list(map(int, input().split())) solve(n, 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
for _ in range(int(input())): n=int(input()) a=list(map(int,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 _ in range(int(input())): n=int(input()) l=[int(x) for x in input().split()] if l[0]+l[1]<=l[len(l)-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
python3
t = int(input()) for case in range(t): n = int(input()) arr = [*map(int,input().split())] if 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
cpp
#include <bits/stdc++.h> using namespace std; long long a[50005]; int main() { int i, t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%lld", &a[i]); } if (a[0] + a[1] <= a[n - 1]) { printf("1 2 %d\n", n); } else { printf("-1\n"); } } 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
cpp
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; int arrg[1000000]; int nxt() { int x; cin >> x; return x; } int lxt() { long long x; cin >> x; return x; } int dxt() { double x; cin >> x; return x; } int ldxt() { long double x; cin >> x; return x; } bool cmp(const pair<int, int> &p, const pair<int, int> &q) { if (p.first < q.first) return 1; else if (p.first == q.first) return (p.second < q.second); else return 0; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc; cin >> tc; for (int z = 1; z <= tc; z++) { long long n = nxt(), p = 1; vector<long long> v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort((v).begin(), (v).end()); long long x = *max_element((v).begin(), (v).end()); for (long long j = 1; j <= n - 2 && p == 1; j++) { if ((v[0] + v[j]) <= x) { cout << 1 << " " << j + 1 << " " << n << "\n"; p = 0; } } if (p) cout << (-1) << "\n"; } 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
cpp
#include <bits/stdc++.h> using namespace std; long long max3(long long a, long long b, long long c) { return max(a, max(b, c)); } long long min3(long long a, long long b, long long c) { return min(a, min(b, c)); } int main() { { int q; cin >> q; while (q--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } bool done = false; 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
# def seg_tree(arr,l,r,seg,ind): # if l==r: # seg[ind] = arr[l] # else: # mid = (l+r)//2 # seg_tree(arr,l,mid,seg,2*ind+1) # seg_tree(arr,mid+1,r,seg,2*ind+2) # seg[ind] = seg[2*ind+1]+seg[2*ind+2] # def get_sum(l1,r1,l2,r2,seg,ind): # if l1==l2 and r1==r2: # return seg[ind] # elif l1 > r1: # return 0 # else: # mid = (l2+r2)//2 # return get_sum(l1,min(r1,mid),l2,mid,seg,2*ind+1) + get_sum(max(l1,mid+1),r1,mid+1,r2,seg,2*ind+2) # def modify(l,r,seg,arr,pos,val,ind): # if l==r: # seg[ind] = val # arr[pos] = val # else: # mid = (l+r)//2 # if pos <= mid: # modify(l,mid,seg,arr,pos,val,2*ind+1) # else: # modify(mid+1,r,seg,arr,pos,val,2*ind+2) # seg[ind] = seg[2*ind+1]+seg[2*ind+2] # n,q = map(int,input().split()) # arr = [0]*n # seg = [None]*(4*len(arr)) # seg_tree(arr,0,len(arr)-1,seg,0) # for i in range(q): # a,b,c = input().split() # if a=="a": # modify(0,len(arr)-1,seg,arr,int(b)-1,(arr[int(b)-1]+int(c))%2,0) # else: # print(int(c)+1-int(b) - get_sum(int(b)-1,int(c)-1,0,len(arr)-1,seg,0)) # def dijksta(graph,edge,n): # Unvisit = {(0,0)} # dist = [0]*n # for i in range(1,n): # Unvisit.add((10000000000,i)) # dist[i] = 10000000000 # while Unvisit: # x = min(Unvisit) # Unvisit.remove(x) # u = x[1] # d = x[0] # for v in graph[u]: # if dist[u] + edge[u][v] < dist[v]: # Unvisit.remove((dist[v],v)) # dist[v] = dist[u] + edge[u][v] # Unvisit.add((dist[v],v)) # return dist[n-1] # def power(x): # if x==0: # return 1 # elif x==1: # return 2 # else: # if x%2==0: # a = power(x//2) # a = a%1000000007 # return (a*a)%1000000007 # else: # a = power(x//2) # a = a%1000000007 # return (2*a*a)%1000000007 for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) x = arr[0] y = arr[1] z = arr[-1] if x+y >z: 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 import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() t = II() for q in range(t): n = II() a = sorted(LI()) 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
import sys LI=lambda:list(map(int, sys.stdin.readline().strip('\n').split())) MI=lambda:map(int, sys.stdin.readline().strip('\n').split()) SI=lambda:sys.stdin.readline().strip('\n') II=lambda:int(sys.stdin.readline().strip('\n')) for _ in range(II()): n=II() a=LI() 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
#!/usr/bin/env python # -*- coding: utf-8 -*- # # untitled.py # # Copyright 2020 Md Sidratul Muntaher Tibrow <smuntahar@gmail.com> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # def main(args): for i in range(int(input())): c = int(input()) n = list(map(int, input().split(' '))) count = 0 v = [] if n[0] + n[1] > n[-1]: print(-1) else: print(1, 2, c) if __name__ == '__main__': import sys sys.exit(main(sys.argv))
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())): g = input() a = [0] + list(map(int, input().split())) if a[1] + a[2] <= a[-1]: print(1, 2, g) 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()) l = [] for k in range(T): N = int(input()) a = list(map(int, input().split())) f=0 for j in range(1,N-1): if a[0]+a[j]<=a[N-1]: l.append([1,j+1,N]) f=1 break if f==0: l.append([-1]) for k in range(T): if l[k][0]==-1: print (-1) else: print (l[k][0],l[k][1],l[k][2])
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())) m=max(l) for i in range(0,n-1): if (l[i]+l[i+1])<=m: print(i+1,i+2,n) 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
import sys from collections import defaultdict # input=sys.stdin.readline for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) if lis[0]+lis[1]<=lis[-1]: print(1,2,n) else: print(-1) # for i in range(int(input())): # s=input() # l=[] # c=0 # for i in s: # if i=="1": # c+=1 # else: # if c!=0: # l.append(c) # c=0 # if c!=0: # l.append(c) # l.sort(reverse=True) # print(sum(l[::2]))
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()) anss = [] for _ in range(t): input() l = list(map(int, input().split(sep=' '))) if l[0] + l[1] > l[-1]: anss.append([-1]) else: anss.append([1, 2, len(l)]) for ans in anss: for i in ans: print(i, end = ' ') print()
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()) a=b=c=0 for i in range(t): f=0 n = int(input()) li = list(map(int,input().split()))[:n] # for j in range(n): # for k in range(j+2,n): # if li[j]+li[j+1]<=li[k]: # a=j+1 # b=j+1+1 # c=k+1 # f=1 # break # if f==1: # break if li[0]+li[1]<=li[len(li)-1]: print(1,2,len(li)) else: print(-1) # if f==1: # print(a,b,c) # 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 t = int(input()) for _ in range(t): n = int(input()) li = list(map(int, input().split()))[:n] if li[0] + li[1] > li[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
for _ in range(int(input())): n=int(input()) data=[int(x) for x in input().split()] if((data[0]+data[1])<=data[n-1]): print(1,2,n) elif((data[n-1]-data[n-2])>=data[0]): print(1,n-1,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 A { static PrintWriter pw; static class FastReader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar, numChars; public FastReader() { this(System.in); } public FastReader(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 next() { 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 i() { 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(next()); } 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 void scanIntArr(int[] arr) { for (int li = 0; li < arr.length; ++li) arr[li] = i(); } public void scanIntIndexArr(int[] arr) { for (int li = 0; li < arr.length; ++li) { arr[li] = i() - 1; } } public void printIntArr(int[] arr) { for (int li = 0; li < arr.length; ++li) pw.print(arr[li] + " "); pw.println(); } public void printLongArr(long[] arr) { for (int li = 0; li < arr.length; ++li) pw.print(arr[li] + " "); pw.println(); } public void scanLongArr(long[] arr) { for (int i = 0; i < arr.length; ++i) { arr[i] = l(); } } public void shuffle(int[] arr) { for (int i = arr.length; i > 0; --i) { int r = (int) (Math.random() * i); int temp = arr[i - 1]; arr[i - 1] = arr[r]; arr[r] = temp; } } public int findMax(int[] arr) { return Arrays.stream(arr).max().getAsInt(); } } public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); pw = new PrintWriter(System.out); int i, j, n, m, temp, t; t = fr.i(); while (t-- > 0) { n = fr.i(); int[] arr = new int[n]; fr.scanIntArr(arr); if (arr[0] + arr[1] <= arr[n - 1]) pw.println(1 + " " + 2 + " " + n); else pw.println(-1); } pw.flush(); pw.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
cpp
#include <bits/stdc++.h> int mod = 1000000007; using namespace std; vector<int> v[100001]; void solve() { long long n; cin >> n; long long 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; } } int main() { int t = 1; cin >> t; while (t--) 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
java
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class A_ { private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static StringTokenizer st; private static int readInt() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public static void main(String[] args) throws IOException { int T = readInt(); while (T-- > 0) solve(); pw.close(); } private static void solve() throws IOException { int n = readInt(); int first = readInt(); int second = readInt(); for (int i = 3; i < n; i++) { readInt(); } int last = readInt(); if (first + second <= last) pw.println("1 2 " + n); else pw.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
cpp
#include <bits/stdc++.h> using namespace std; double pi = 3.14159265358979323846; bool sortbysec(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.first == b.first) return (a.second < b.second); return (a.first < b.first); } long long int fpower(long long int x, long long int y) { long long int ans = 1; while (y) { if (y & 1) ans = ans * x, y--; else x *= x, y /= 2; } return ans; } long long int myXOR(long long int x, long long int y) { return (x | y) & (~x | ~y); } bool prime(long long int x) { if (x == 1) return 0; for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) return 0; } return 1; } long long int gcd(long long int x, long long int y) { if (x == 0) return y; return gcd(y % x, x); } void primefactor(set<long long int> &s, long long int x) { for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) { s.insert({i, x / i}); } } } int count(string s, string s1, int n, int m, int sum) { if (n == 0 || m == 0) return 0; if (s[n - 1] == s1[m - 1]) sum = max(sum + 1, count(s, s1, n - 1, m - 1, sum + 1)); else sum = max(sum, max(count(s, s1, n - 1, m, 0), count(s, s1, n, m - 1, 0))); return sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int k; cin >> k; while (k--) { int n, x; cin >> n; vector<int> v; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } int flag = 0; int l = 0, r, i = n - 1; for (r = 1; r < i; r++) { if (v[i] >= v[l] + v[r]) { flag = 1; break; } } if (flag) { cout << l + 1 << " "; cout << r + 1 << " "; cout << i + 1 << "\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
# -*- coding: utf-8 -*- """ Created on Sat Aug 15 22:54:54 2020 @author: user """ t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) if(arr[0]+arr[1]<=arr[-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
for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] x=a[0] y=a[1] found=False for i in range(n-2): z=a[2+i] if(x+y<=z): found=True print(1,2,i+3) break if not found: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())) a.sort() if a[0] + a[1] <= a[-1]: print(1, 2, n) elif a[0] >= a[-2] + a[-1]: print(1, n-1, 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): n=int(input()) a=list(map(int,input().split())) b,c,e=a[0],a[1],a[-1] if(b+c<=e): print("1 2 %d"%(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 math m=1000000007 def fact(n): ans=1 for i in range(1,n+1): ans=((ans%m)*(i%m))%m return ans def power_2(n): ans=1 for i in range(n): ans=((ans%m)*(2))%m return ans for z in range(int(input())): n=int(input()) flag=True a=[int(i) for i in input().split()] for i in range(n-2): if(a[i]+a[i+1]<=a[n-1]): flag=False print(i+1,i+2,n) break if(flag): 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 ()) inn =[] result=[] c=0 for j in range(t): n = int (input()) inn = [int (a) for a in input().split()] if ((((inn[0]+inn[1])>inn[n-1]) & ((inn[0]+inn[n-1])>inn[1]) & ((inn[1]+inn[n-1])>inn[0])) & (((inn[n-1]+inn[n-2])>inn[0]) & ((inn[n-1]+inn[0])>inn[n-2]) & ((inn[0]+inn[n-2])>inn[n-1]))): result.append("-1") else: result.append([1,2,n]) for i in result: if (type(i) == list): for j in i: if (c!=(len(i)-1)): print(j, end=' ') c=c+1 else: print(j) c=0 else: print(i)
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 long long LINF = (long long)1e18 + 47; const int INF = 2 * 1e9 + 47; const int MOD = 1e9 + 7; const int modulo = 1e8; const int nax = 3 * (int)1e3 + 10; const double EPS = 1e-7; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int tt; cin >> tt; for (int test = (1); test < (tt + 1); test++) { int n; 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
import math import sys from collections import Counter from math import factorial as fact from collections import defaultdict def inpint(): return int(input()) def inpstr(): return str(input()) def inparr(): return list(map(int,input().strip().split())) def inptup(): return map(int,input().strip().split()) #---------------------------------------------------------------------------- for _ in range(int(input())): 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
python3
n=int(input()) for i in range(n): flag=0 m=int(input()) a=[int(x) for x in input().split()] if a[0]+a[1]<=a[-1]: print(1,2,m) 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())) 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() { long long int t, k; cin >> t; for (k = 1; k <= t; k++) { long long int n, i, s = 0, f = 0; cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } s = a[0] + a[1]; for (i = 2; i < n; i++) { if (a[i] >= s) { f = 1; cout << 1 << " " << 2 << " " << i + 1; break; } } if (f == 0) cout << -1; cout << 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
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t, n, i; cin >> t; while (t--) { cin >> n; int ar[n]; for (i = 0; i < n; i++) cin >> ar[i]; if (ar[0] + ar[1] <= ar[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
java
import java.util.*; public class ECR_92_A { 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(); System.out.println(a[0]+a[1]<=a[n-1]?"1 2 "+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
t = int(input()) while t: n = int(input()) sides = list(map(int, input().split())) if sides[0] + sides[1] > sides[-1]: print(-1) else: print(1, 2, n) 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
cpp
#include <bits/stdc++.h> using namespace std; const int MXN = 5e4 + 5; const int INF = 1e9; const long long P = 29; const long long MOD = 1e9 + 7; int t; int main() { srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); cin >> t; while (t--) { int n, x1, x2, x3; cin >> n; cin >> x1 >> x2; for (int i = 2; i < n; i++) { cin >> x3; } if (x1 + x2 <= x3) cout << 1 << ' ' << 2 << ' ' << n << '\n'; else cout << -1 << '\n'; } 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
java
//note: 0<=|int|<=2 * 10^9 //note: 0<=|long|<= 9 * 10^18 //note: 20! max w/ long //note: 91st fibonacci # highest calculable w/long //note: 0 <= |double| <= 1.8 * 10^308 //note: 170! max w/long; import java.io.*; import java.util.*; import java.math.BigInteger; public class CP{ private static StringTokenizer st; private static BufferedReader br; private static int MAX = Integer.MAX_VALUE; private static int MIN = Integer.MIN_VALUE; private static List<Integer> adj[]; // private static List<String> adj[]; // use this for a graph public static void main(String[] args) throws IOException{ FastScanner sc = new FastScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextint(); for(int i = 0; i < t; i++) { int n = sc.nextint(); int[] nums = new int[n]; for(int j = 0; j < n; j++) { nums[j] = sc.nextint(); } if(nums[0] + nums[1] <= nums[nums.length-1]) { out.println(1 + " " + 2 + " " + (nums.length)); } else { out.println(-1); } } out.close(); } private static int search(int[] nums, int m) { int left = 0; int right = nums.length - 1; while(left < right) { int mid = left + (right-left)/2; if(nums[mid] > m) { right = mid; } else if(nums[mid] <= m) { left = mid + 1; } } return left; } private static void dfs(List<Point> cur, int r, int c, int[][] dir, boolean[][] vis){ if(!vis[r][c]) { vis[r][c] = true; Point p = new Point(r, c); cur.add(p); for(int[] d : dir) { int newR = r + d[0]; int newC = c + d[1]; if(newR >= 0 && newR < vis.length && newC >= 0 && newC < vis.length && !vis[newR][newC]) { dfs(cur, newR, newC, dir, vis); } } } } private static class Point{ int r, c; public Point(int r, int c) { this.r = r; this.c = c; } } private static class FenTree{ private long[] tree; public FenTree(int size) { tree = new long[size+1]; } public void add(int index, int add) { while(index < tree.length) { tree[index] += add; index += (index & -index); } } public long sum(int index) { long sum = 0; while(index > 0) { sum += tree[index]; index -= (index & -index); } return sum; } } public static int f(int k) { if(k == 0 || k == 1) { return 1; } return f(k-1) + f(k-2); } public static int fib(int k, int[] dp2) { if(dp2[k] != MAX) { return dp2[k]; } else if(k == 0 || k == 1) { dp2[k] = 1; return 1; } dp2[k] = fib(k-1, dp2) + fib(k-2, dp2); return dp2[k]; } public static boolean contains(List<Integer> arr, int key){ int left = 0; int right= arr.size(); while(left < right){ int mid = left + (right-left)/2; if(arr.get(mid) == key){ return true; } else if(arr.get(mid) < key){ left = mid +1; } else{ right = mid; } } return false; } private static long modInverse(long a, long b) { long bb = b, temp, q; long x0 = 0, x1 = 1; if(b == 1){ return 1L; } while(a > 1){ q = a/b; temp = b; b = a%b; a=temp; temp = x0; x0 = x1-q*x0; x1 = temp; } if(x1 < 0){ x1 += bb; } return x1; } private static int gcd(int a, int b){ if(a == 0){ return b; } return gcd(b%a, a); } private static PrintWriter out; private static class FastScanner{ public FastScanner(){ 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; } } }
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
#list (map(int, input().split())) rw = int(input()) for qwe in range(rw): n = int(input()) a = list(map(int, input().split())) a.reverse() if a[0] >= a[n - 2] + 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
t = int(input()) for _ in range(t): n = int(input()) arr = [int(i) for i in input().split()] if arr[0]+arr[1] <= arr[-1]: print(0+1,1+1,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 main(): for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) if (a[0]+a[1])<=a[-1]: print(1,2,n) else: 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
python3
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] <= a[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
T = int(input()) for t in range(T): n = int(input()) a = [int(x) for x in 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
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) 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; template <typename T> void pr(vector<T> &v) { for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " "; cout << endl; } template <typename T> void pr(vector<vector<T>> &v) { for (int i = 0; i < (int)(v).size(); i++) { pr(v[i]); } } template <typename T> void re(T &first) { cin >> first; } template <typename T> void re(vector<T> &a) { for (int i = 0; i < (int)(a).size(); i++) re(a[i]); } template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); } template <typename T> void pr(T first) { cout << first << endl; } template <class Arg, class... Args> void pr(const Arg &first, const Args &...rest) { cout << first << " "; pr(rest...); cout << endl; } void ps() { cout << endl; } template <class T, class... Ts> void ps(const T &t, const Ts &...ts) { cout << t; if (sizeof...(ts)) cout << " "; ps(ts...); } void solve() { int n; re(n); vector<int> a(n); re(a); if (a[0] + a[1] <= a[n - 1]) { ps(1, 2, n); } else { pr(-1); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; re(t); for (int tt = 0; tt < t; tt++) { 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
try: t=int(input()) for _ in range(t): n=int(input()) flag=0 a=list(map(int,input().split())) if a[-1] >= a[0]+a[1]: print(1,2,n) else: print(-1) except: pass
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()) lis = [int(a) for a in input().split()] i = 0 j = n-1 istrue = True while(j >= 2) and istrue: while(i <= j-2) and istrue: if(lis[j] >= lis[i]+lis[i+1]): print(i+1, i+2, j+1) istrue = False break i += 1 j -= 1 if(istrue): 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
n = int(input()) for i in range(n): y = int(input()) a = list(map(int, input().split())) p = 0 q = 0 for k in range(2, y): if(a[0]+a[1]<=a[k]): p = 1 q = k+1 break if(p==0): print(-1) else: print(p, p+1, q)
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())) x=a[0]+a[1] flag=0 for i in range(2,len(a)): if(a[i]>=x): print(1,2,i+1) 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
import sys #another one inp=sys.stdin.buffer.readline inin=lambda : int(inp()) inar=lambda typ=int: list(map(typ,inp().split())) inst=lambda : inp().decode().strip() _T_=inin() for _t_ in range(_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
java
import java.util.*; public class BadTriangle { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int t1=1;t1<=t;t1++) { int n=sc.nextInt(); long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=sc.nextLong(); int flag=0,z=0; long x=a[0]; long y=a[1]; for(int i=2;i<n;i++) { if(x+y<=a[i]) { z=i+1; flag=1; break; } } if(flag==1) System.out.println(1+" "+2+" "+z); 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
cpp
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long INF = 1LL << 62; const long long MINF = -(1LL << 62); template <typename T> T getint() { T val = 0; char c; bool neg = false; while ((c = getchar()) && !(c >= '0' && c <= '9')) { neg |= c == '-'; } do { val = (val * 10) + c - '0'; } while ((c = getchar()) && (c >= '0' && c <= '9')); return val * (neg ? -1 : 1); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) { int n; cin >> n; vector<int> t(n); for (int i = 0; i < n; ++i) cin >> t[i]; if (t[0] + t[1] > t[n - 1]) { cout << "-1\n"; } else { cout << "1 2 " << n << "\n"; } } 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())): input() a = list(map(int,input().split())) if a[0]+a[1]<=a[-1]: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 _ in range(int(input())): n = int(input()) *arr, = map(int, input().split()) # indices= sorted(range(n), key=lambda idx: arr[idx]) if arr[0] + arr[1] <= arr[-1]: print(1, 2, len(arr)) 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()) l=[int(i) for i in input().split()] if l[0]+l[1]>l[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
for _ in range(int(input())): 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
for t in range(int(input())): n=int(input()) a=[int(i) for i in input().split()] x=1 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
a = int(input()) for i in range(a): b = int(input()) c = list(map(int,input().split())) if c[0] + c[1] > c[-1]: print(-1) else: print(1, 2, len(c))
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; } }
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.math.*; import java.io.*; public class B{ static int[] dx={-1,1,0,0}; static int[] dy={0,0,1,-1}; static FastReader scan=new FastReader(); public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); static ArrayList<Pair>es; static LinkedList<Integer>edges[]; static boolean prime[]; static void sieve(int n) { prime = new boolean[n+1]; for(int i=0;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; } } } public static int lowerBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; //checks if the value is less than middle element of the array if (value <= array[mid]) { high = mid; } else { low = mid + 1; } } return low; } public static int upperBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = low+(high-low) / 2; if ( array[mid]>value) { high = mid ; } else { low = mid+1; } } return low; } static long mod(long x,long y) { if(x<0) x=x+(-x/y+1)*y; return x%y; } static boolean isPowerOfTwo(int n) { if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static boolean isprime(long x) { for(long i=2;i*i<=x;i++) if(x%i==0) return false; return true; } static int dist(int x1,int y1,int x2,int y2){ return Math.abs(x1-x2)+Math.abs(y1-y2); } static long cuberoot(long x) { long lo = 0, hi = 1000005; while(lo<hi) { long m = (lo+hi+1)/2; if(m*m*m>x) hi = m-1; else lo = m; } return lo; } public static int log2(int N) { // calculate log2 N indirectly // using log() method int result = (int)(Math.log(N) / Math.log(2)); return result; } static long gcd(long a, long b) { if(a!=0&&b!=0) while((a%=b)!=0&&(b%=a)!=0); return a^b; } static long LCM(long a,long b){ return (Math.abs(a*b))/gcd(a,b); } public static class comp1 implements Comparator<Pair>{ public int compare(Pair o1,Pair o2){ if(o2.x==o1.x) return (o2.y-o1.y)>0?1:-1; return (o2.x-o1.x)>0?1:-1; } } public static class comp2 implements Comparator<Pair>{ public int compare(Pair o1,Pair o2){ return (o2.ab-o1.ab)>0?1:-1; } } static boolean can(int m,int s) { return (s>=0&&s<=m*9); } static boolean collinear(long x1, long y1, long x2, long y2, long x3, long y3) { long a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2); if(a==0) return true; return false; } static double arr[]; static int n; static double l; static boolean ok(double x) { //out.println(x); for(int i=0;i<n-1;i++) { if(i==0&&arr[0]!=0) { if(arr[i]-x>0) return false; } if(Double.compare(arr[i], arr[i+1]) == 0){ //out.println("FUCK"); continue; } if(Double.compare(arr[i]+x, arr[i+1]-x) < 0) { // out.println(arr[i]+" "+arr[i+1]+" "+x); return false; } } if(arr[n-1]<l) { if(arr[n-1]+x<l) return false; } return true; } public static void main(String[] args) throws Exception { //java.util.Scanner scan=new java.util.Scanner(new File("mootube.in")); //PrintWriter out = new PrintWriter (new FileWriter("mootube.out")); //scan=new FastReader("equal.in"); //out = new PrintWriter ("output.txt"); //System.out.println(3^2); //System.out.println(19%4); //StringBuilder news=new StringBuilder("ab"); //news.deleteCharAt(1); //news.insert(0,'c'); //news.deleteCharAt(0); //System.out.println(news); //System.out.println(can(2,15)); int tt=1; tt=scan.nextInt(); /* PriorityQueue<Pair>tree=new PriorityQueue<Pair>(); tree.add(new Pair(3,7)); tree.add(new Pair(3,5)); Pair pp=new Pair(3,5); tree.remove(pp); pp=new Pair(3,7); */ //System.out.println(tree.remove(pp)); //System.out.println(tree.remove(pp)); //System.out.println(tree.peek().x); outer:while(tt-->0) { int n=scan.nextInt(); long arr[]=new long[n]; for(int i=0;i<n;i++) { arr[i]=scan.nextLong(); } for(int i=0;i<n-2;i++){ if(arr[i]+arr[i+1]<=arr[n-1]||arr[i]+arr[i+1]<=arr[n-1]&&arr[i]+arr[i+1]<=arr[n-1]) { out.println((i+1)+" "+(i+2)+" "+(n)); continue outer; } } //out.println(-1); out.println(-1); //out.println(res); //out.println(arr[0]+" "+arr[1]+" "+arr[2]); } out.close(); } static long binexp(long a,long n,long mod) { if(n==0) return 1; long res=binexp(a,n/2,mod)%mod; res=res*res; if(n%2==1) return (res*a)%mod; else return res%mod; } static class special implements Comparable<special> { char x; int id; special(char x,int id) { this.id=id; this.x=x; } public int compareTo(special o) { return o.id-id; } } public static long pow(long b, long e) { long r = 1; while (e > 0) { if (e % 2 == 1) r = r * b ; b = b * b; e >>= 1; } return r; } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int object : arr) list.add(object); Collections.sort(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } public static class FastReader { BufferedReader br; StringTokenizer root; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } FastReader(String filename)throws Exception { br=new BufferedReader(new FileReader(filename)); } String next() { while (root == null || !root.hasMoreTokens()) { try { root = new StringTokenizer(br.readLine()); } catch (Exception addd) { addd.printStackTrace(); } } return root.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception addd) { addd.printStackTrace(); } return str; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) { array[i] = nextInt(); } return array; } } public static class Pair implements Comparable<Pair>{ long x; long y; long ab; int z; public Pair(){} public Pair(long x1, long y1,int z) { x=x1; y=y1; this.z=z; } public Pair(long x1, long y1) { x=x1; y=y1; this.ab=x+y; } @Override public int hashCode() { return (int)(x + 31 * y); } public String toString() { return x + " " + y; } @Override public boolean equals(Object o){ if (o == this) return true; if (o.getClass() != getClass()) return false; Pair t = (Pair)o; return t.x == x && t.y == y; } public int compareTo(Pair o) { return (int)(o.x-x); } } }
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 findTriangle(arr,n): if n < 3: return -1 i = 0 j = 1 k = 2 while k < n-1: if (arr[i]+arr[j] <= arr[k]) or (arr[j]+arr[k] <= arr[i]) or (arr[i]+arr[k] <= arr[j]): return str(i+1)+" "+str(j+1)+" "+str(k+1) k+=1 while j<n-2: if (arr[i]+arr[j] <= arr[k]) or (arr[j]+arr[k] <= arr[i]) or (arr[i]+arr[k] <= arr[j]): return str(i+1)+" "+str(j+1)+" "+str(k+1) j+=1 while i<n-2: if (arr[i]+arr[j] <= arr[k]) or (arr[j]+arr[k] <= arr[i]) or (arr[i]+arr[k] <= arr[j]): return str(i+1)+" "+str(j+1)+" "+str(k+1) i+=1 return -1 t = int(input()) main_arr = [] n_s = [] for a in range(0,t): n = int(input()) n_s.append(n) arr = input().rstrip().split(" ") for b in range(0,n): arr[b] = int(arr[b]) main_arr.append(arr) for c in range(0,t): print(findTriangle(main_arr[c],n_s[c]))
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()) l=list(map(int,input().split())) s=l[0]+l[1] for i in range(2,n): if l[i]>=s: print(1,2,i+1) break 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
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) if(l[0]+l[1] > l[-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): n = int(input()) ar=list(map(int,input().split())) if(ar[0]+ar[1]<=ar[n-1]): print('1 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
python3
import math import time from collections import defaultdict,deque,Counter from sys import stdin,stdout from bisect import bisect_left,bisect_right from queue import PriorityQueue import sys t=1 t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,stdin.readline().split())) if(a[-1]>=a[0]+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()) for i in range(t): n=int(input()) a=[int(i) for i in input().split()] v=a[0]+a[1] a=a[2:] f=0 for i in range(len(a)): if(v<=a[i]): print("1 2",i+3,end='\n') f=1 break if(not f): print("-1",end='\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
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void r(int arr[],int l,int m,int r) { int n1=m-l+1; int n2=r-m; int L[]=new int[n1]; int R[]=new int[n2]; for(int i=0;i<n1;i++) { L[i]=arr[l+i]; } for(int j=0;j<n2;j++) { R[j]=arr[m+1+j]; } int i=0; int j=0; int k=l; while(i<n1 && j<n2) { if(L[i]<=R[j]) { arr[k]=L[i]; ++i; } else{ arr[k]=R[j]; ++j; } ++k; } while(i<n1) { arr[k]=L[i]; ++i; ++k; } while(j<n2) { arr[k]=R[j]; ++j; ++k; } } public static void r2(int arr[],int l,int r) { if(l<r) { int m=(l+r)/2; r2(arr,l,m); r2(arr,m+1,r); r(arr,l,m,r); } } 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 static void main (String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t=sc.nextInt(); for(int test=0;test<t;test++){ int n=sc.nextInt(); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextLong(); } long aa=arr[0]; long bb=arr[1]; long ee=arr[n-3]; long cc=arr[n-1]; long dd=arr[n-2]; if(n>3){ long x=aa+bb; long y=cc-dd; if(cc>=x){ System.out.println(1+" "+2+" "+n); } else if(y>=ee){ System.out.println((n-2)+" "+(n-1)+" "+n); } else{ System.out.println("-1"); } } else{ if((aa+bb)<=cc){ System.out.println(1+" "+2+" "+3); } 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
def f(k,arr): #assert (j==len(arr)) a=arr[0] b=arr[1] for i in range(k): if arr[i]>=(a+b): return('1 2 '+str(i+1)) return '-1' a=input() n=int(a) for i in range(n): j=int(input()) a=list(map(int,input().rstrip().split())) print(f(j,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
java
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class BadTriangle implements Closeable { private InputReader in = new InputReader(System.in); private PrintWriter out = new PrintWriter(System.out); public void solve() { int t = in.ni(); while (t-- > 0) { int n = in.ni(); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = in.ni(); } if (isTriangle(x[0], x[1], x[n - 1])) { out.println(-1); } else { out.println("1 2 " + n); } } } private boolean isTriangle(int a, int b, int c) { return a + b > c && a + c > b && b + c > a; } @Override public void close() throws IOException { in.close(); out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public void close() throws IOException { reader.close(); } } public static void main(String[] args) throws IOException { try (BadTriangle instance = new BadTriangle()) { instance.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
from sys import stdin def main(): input = lambda: stdin.readline()[:-1] T = int(input()) for _ in [0] * T: N = int(input()) A = list(map(int, input().split())) if A[0] + A[1] <= A[-1]: print(1, 2, N) else: print(-1) 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 sys from math import ceil, factorial, gcd #from math import comb, perm only in python3 from collections import Counter, deque, defaultdict from bisect import bisect_left, bisect_right from heapq import heappop, heappush, heapify MOD = 10**9 + 7 INF = float('inf') rl = lambda : list(map(int, sys.stdin.readline().split())) rs = lambda : sys.stdin.readline().strip() for _ in range(int(input())): n = int(input()) A = rl() print(1, 2, n) if A[0] + A[1] <= A[-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
for t in range(int(input())): n = int(input()) a = list(map(int,input().split(" "))) a.sort() 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
java
import java.util.*; import java.io.*; public final class BadTriangle{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0;i<n;i++){ int numLengths=sc.nextInt(); TreeMap<Integer,TreeSet<Integer>> triangleSides=new TreeMap<Integer,TreeSet<Integer>>(); int sidesArray[]=new int[numLengths]; for(int j=0;j<numLengths;j++){ int side=sc.nextInt(); triangleSides.putIfAbsent(side,new TreeSet<Integer>()); triangleSides.get(side).add(j); sidesArray[j]=side; } boolean flag=true; for(int k=0;k<numLengths-2;k++){ int val=sidesArray[k]+sidesArray[k+1]; Map.Entry<Integer,TreeSet<Integer>> nxtEntry=triangleSides.ceilingEntry(val); if(nxtEntry!=null){ if(nxtEntry.getValue().ceiling(k+2)!=null){ int nxtPos=nxtEntry.getValue().ceiling(k+2); System.out.println(String.format("%d %d %d",k+1,k+2,nxtPos+1)); flag=false; break; } } } if(flag){ System.out.println(String.format("%d",-1)); } } } }