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
java
// No sorceries shall prevail. // import java.util.*; import java.io.*; public class InVoker { //Variables static long mod = 1000000007; static long mod2 = 998244353; static FastReader inp= new FastReader(); static PrintWriter out= new PrintWriter(System.out); public static void main(String args[]) { InVoker g=new InVoker(); g.main(); out.close(); } //Main void main() { int t=inp.nextInt(); while(t-->0) { int n=inp.nextInt(); long a[]=new long[n]; input(a,n); if(a[0]+a[1]>a[n-1]) { out.println(-1); }else { out.println("1 2 "+n); } } } static class Pair implements Comparable<Pair> { long f, s; Pair () {} Pair (long l_, long r_) { this.f = l_; this.s = r_; } @Override public int compareTo(Pair other) { if(this.f==other.f) { return Long.compare(this.s,other.s); } return Long.compare(this.f, other.f); } } static class Segment implements Comparable<Segment> { long l, r, initialIndex; Segment () {} Segment (long l_, long r_, long d_) { this.l = l_; this.r = r_; this.initialIndex = d_; } @Override public int compareTo(Segment o) { return (int)((l - o.l) !=0 ? l-o.l : initialIndex - o.initialIndex); } } /********************************************************************************************************************************************************************************************************* * ti;. .:,:i: :,;;itt;. fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE :,:. f::::. .,ijLGDDDDDDDEEEEEEE* *ti;. .:,:i: .:,;itt;: GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG. .::. f:,...,ijLGDDDDDDDDEEEEEE * *ti;. .:,:i: :,;;iti, :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG .::. .f,::,ijLGDDDDDDDDEEEEEE * *ti;. .:,:i: .,,;iti;. LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj .::. .:L;;ijfGDDDDDDDDDEEEEE * *ti;. .:,:i: .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL .::. .:;LijLGGDDDDDDDDEEEEE * *ti;. .:,:;: :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj .::. :,;jffGGDDDDDDDDDEEEE * *ti;. .:,:i: .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL .::. .:;itDGGDDDDDDDDDEEEE * *ti;. .:::;: :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf .::. :,itfGEDDDDDDDDDDDEE * *ti;. .:::;: :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG .::. .,;jfLGKDLDDDDDDEEDD * *ti;. .:::;: fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::. .,;tfLGDEDDDDDDDDEEE * *ti;. :::;: fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::. .,;tfLGDDDKDDDDDDDDD * *ti;. .::;: fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:. .,;tfLGGDDDKDDDDDDDD * *ti;. .:.;: tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::. .,;tfLGGDDDDEDDDDDDD * *ti;. .::;: fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::. .,;tfLGGDDDDDDEDDDDD * *ti;. .:.;: tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::. .,;tfLGGDDDDDDDEDDDD * *ti;. .:.,. LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:. .,;tfLGGDDDDDDDDEDDD * *ti;. ..:.,. LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,. .,;tfLGGDDDDDDDDDKDD * *tt;. .:.,: jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,: .,;tfLGGDDDDDDDDDDKD * *tii,. .:.,. tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,. .,;tfLGGDDDDDDDDDDDE * *ti;;,:. .:.,: fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,. .,;tfLGGDDDDDDDDDDDD * *tii;,,:.. ...,. ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,: .,itfLGGDDDDDDDDDDDD * *ti;,,,,,:. ...,. LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:. .,itfGGGDDDDDDDDDDDD * *tii,,,,::::. ...,: .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:. .,ijfGGGDDDDDDDDDDDD * *ti;:::::::::.. .:.,: LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,: .,ijLGGGDDDDDDDDDDDD * *tt;. .::::::::.. ...,: :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:. .:,;,:. .,ijLGGDDDDDDDDDDDDD * *tt;. .:::::::.. ...,: GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,. :,,,:...,ijLGGGDDDDDDDDDDDD * *tt;. .....::::.. ...,: fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi. .,;,:::,ijLGGGDDDDDDDDDDDD * *tt;. ....:::::. ...,. iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff. .:,;,,;ijLGGGDDDDDDDDDDDD * *tt;. ....::::.. .:.,: .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG. .:,;;iijLGGGDDDDDDDDDDDD * *tt;. .....:::.. ...,. .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG. :,iitjLGGGDDDDDDDDDDDD * *tti. .....:::.. ...,. GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf. .,;tjfLGGDDDDDDDDDDDD * *tti. ....::::.. ...,. fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf. :;ijfLGGDDDDDDDDDDDD * *tti. ....::::.. ...,. LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf: .,itfLGGDDDDDDDDDDDD * *tti. .....:::.. ...,. fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi .,;tfLGGGDDDDDDDDDDD * *tti. .....:::.. ...,. iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL .,;tjLLGGDDDDDDDDDDD * *tti. ....::::......:. LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG .,;tjLLGGDDDDDDDDDDD * *tti. ...::::::..,. :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL .,;tjLLGGDDDDDDDDDDD * *tti. ....::::::,. GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf .,;tjLLGGDDDDDDDDDDD * *tti. ....:::,,. .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf .:;tjLLGGGDDDDDDDDDD * *tti. ...::,,,:. GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf .:;tjLLGGDDDDDDDDDDD * *jti. ...::,,,,:. .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf: .,;tfLLGGDDDDDDDDDDD * *tti. ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi .,;tfLLGGGDDDDDDDDDD * *tti. ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL .,;tfLGGGDDDDDDDDDDD * *jti. ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG .,;tfLGGGGDDDDDDDDDD * *jti. ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL .,;tfLGGGGDDDDDDDDDD * *jti. ...:. .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf .,;tfGGGGDDDDDDDDDDD * *jti. ...:. ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:. .,;tfGGGGDDDDDDDDDDD * *jti. ...:. GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,: .,;tfGGGGDDDDDDDDDDD * *jti. ...:. GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK, ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD * *jti. ...:. fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG .:,,,:::,;tfGGGDDDDDDDDDDDD * *jti. ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL .:,;,,,;tfGGGDDDDDDDDDDDD * *jti. ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf .:,;;;itfGGGDDDDDDDDDDDD * *jti. ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf .,;iitfGGGDDDDDDDDDDDD * *jti. ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL .:;itfGGGDDDDDDDDDDDD * *jji. ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j. KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf .,;tfGGGDDDDDDDDDDDD * *jji. ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;.................................. . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL, .:;tfGGGDDDDDDDDDDDD * *jji. .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................:: KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj .:;tfGGDDDDDDDDDDDDD * *jji. .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG .:;tfGGGDDDDDDDDDDDD * *jji. . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG .;tjfLLGDDDDDDDDDDDDDDD * *jji. i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL ,fGGGDDDDDDDDEEEDDDDDDDDDD * *jji. .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD * *jji. i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD * *jji. .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD * *jji. .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL; .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD * *jji. :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED * *jji. i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE * *jji. i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD * *jji. .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG * *jjt. :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG * *jji. ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG * *jjt. f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG * *jjt. ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG * *fji. ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL * *fji. t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL * *fjt: .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL * *fjji;:. .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG * *fjjtii;,:. :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG * *fjtiiiii;;:. j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG * *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG * *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD * *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD * *fjt. .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD * *fjt. .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD * *fjt. .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD * *fjt: :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD * *fjt: t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD * *jjt. f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD * *fjt:. ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG * *fjt:. ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; * *fjt:. f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, * *fjt:. .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, * *fjt:. .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, * *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, * *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, * *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; * *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; * *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; * ***********************************************************************************************************************************************************************************************************/ // Classes 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 s=""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } // Functions static long gcd(long a, long b) { return b==0?a:gcd(b,a%b); } static int gcd(int a, int b) { return b==0?a:gcd(b,a%b); } //Input Arrays static void input(long a[], int n) { for(int i=0;i<n;i++) { a[i]=inp.nextLong(); } } static void input(int a[], int n) { for(int i=0;i<n;i++) { a[i]=inp.nextInt(); } } static void input(String s[],int n) { for(int i=0;i<n;i++) { s[i]=inp.next(); } } static void input(int a[][], int n, int m) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { a[i][j]=inp.nextInt(); } } } static void input(long a[][], int n, int m) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { a[i][j]=inp.nextLong(); } } } }
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.*; import java.util.concurrent.TimeUnit; public class a1398 implements Runnable{ public static void main(String[] args) { try{ new Thread(null, new a1398(), "process", 1<<26).start(); } catch(Exception e){ System.out.println(e); } } public void run() { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //PrintWriter out = new PrintWriter("file.out"); Task solver = new Task(); int t = scan.nextInt(); //int t = 1; for(int i = 1; i <= t; i++) solver.solve(i, scan, out); out.close(); } static class Task { static final int inf = Integer.MAX_VALUE; public void solve(int testNumber, FastReader sc, PrintWriter out) { int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++) { arr[i] = sc.nextInt(); } if(arr[0] + arr[1] <= arr[N-1]) { out.println("1 2 " + (N)); } else { out.println(-1); } } } static long binpow(long a, long b, long m) { a %= m; long res = 1; while (b > 0) { if ((b & 1) == 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } static void sort(int[] x){ shuffle(x); Arrays.sort(x); } static void sort(long[] x){ shuffle(x); Arrays.sort(x); } static class tup implements Comparable<tup>, Comparator<tup>{ int a, b; tup(int a,int b){ this.a=a; this.b=b; } public tup() { } @Override public int compareTo(tup o){ return Integer.compare(b,o.b); } @Override public int compare(tup o1, tup o2) { return Integer.compare(o1.b, o2.b); } @Override public int hashCode() { return Objects.hash(a, b); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; tup other = (tup) obj; return a==other.a && b==other.b; } @Override public String toString() { return a + " " + b; } } static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } 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
t = int(input()) while t > 0: n = int(input()) # s = input() # n, m = map(int, input().split()) a = list(map(int, input().split())) # b = list(map(int, input().split())) i = 0 k = n-1 j = -1 for it in range(1,n-1): if a[i]+a[it]<=a[k]: j = it break if j == -1: print(-1) else: print(i+1,j+1,k+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
t = int(input()) for _ in range(t): n = int(input()) array = list(map(int, input().split())) if array[0] + array[1] <= array[-1]: print(1, 2, len(array)) 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. Bad Triangle 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
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] > a[-1]: print(-1) else: print(1, 2, len(a))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) x=[int(x) for x in input().split()] if x[0]+x[1]<=x[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()) n = [] sides = [] for _ in range(t): n.append(int(input())) sides.append(list(map(int, input().split()))) for te in range(t): found = 0 if sides[te][0] + sides[te][1] <= sides[te][n[te]-1]: print(1, 2, n[te]) found = 1 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
#code import bisect for _ in range(int(input())): n=int(input()) a=[int(s) for s in input().split()] i=0 j=0 f=0 while(i<n-1): s=a[i]+a[i+1] j=bisect.bisect_left(a,s) if j<n: f=1 break i+=1 if f: print(i+1,i+2,j+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
z,zz=input,lambda:list(map(int,z().split())); szz,dgraphs,mod=lambda:sorted(zz()),{},10**9+7 from string import * from collections import * from queue import * from sys import * from collections import * from math import * from heapq import * from itertools import * from bisect import * from collections import Counter as cc from math import factorial as f from bisect import bisect as bs from itertools import accumulate as ac def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2)) def prime(x): p=ceil(x**.5)+1 for i in range(2,p): if x%i==0 and x!=2:return 0 return 1 def dfs(u,visit,graph): visit[u]=True for i in graph[u]: if not visit[i]: dfs(i,visit,graph) ###########################---Test-Case---################################# """ """ ###########################---START-CODING---############################## num=int(z()) for _ in range(num): n=int(z()) l=zz() a=l[0] b=l[1] c=l[-1] if a+b>c and b+c>a and a+c>b: 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; int main() { long long t, n; long long arr[1000000]; cin >> t; for (int a = 1; a <= t; a++) { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } if (arr[0] + arr[1] <= arr[n - 1]) { cout << 1 << " " << 2 << " " << n << "\n"; } else cout << -1 << "\n"; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for i 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
#input template from sys import stdin, stdout from collections import Counter, OrderedDict import math cin = stdin.readline cout = stdout.write mp = lambda: list(map(int, cin().split())) def chars(): #function for taking string input as character array since string in python is immutable s = cin() return(list(s[:len(s) - 1])) #print list def pl(a): for val in a: cout(str(val) + ' ') cout('\n') #main t, = mp() for _ in range(t): n, = mp() a = mp() if a[0] + a[1] > a[-1]: cout('-1\n') else: pl([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
from functools import reduce import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase input = lambda: sys.stdin.readline().rstrip("\r\n") def value():return tuple(map(int,input().split())) def arr():return [int(i) for i in input().split()] def sarr():return [int(i) for i in input()] def inn():return int(input()) mo=1000000007 #----------------------------CODE------------------------------# for _ in range(int(input())): n=inn() a=arr() 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; using ull = unsigned long long; using ll = long long int; ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) { res = res * a; } a = a * a; b >>= 1; } return res; } void solve() { ll n; cin >> n; ll ar[n + 1]; for (ll i = 0; i < n; i++) { cin >> ar[i]; } ll mn[n + 1]; ll mx[n + 1]; mn[0] = 0; for (ll i = 1; i < n; i++) { if (ar[i] < ar[mn[i - 1]]) { mn[i] = i; } else { mn[i] = mn[i - 1]; } } mx[n - 1] = n - 1; for (ll i = (n - 2); i >= 0; i--) { if (ar[i] > ar[mx[i + 1]]) { mx[i] = i; } else { mx[i] = mx[i + 1]; } } for (ll i = 0; i < n; i++) { if ((ar[i] + ar[mn[i]] <= ar[mx[i]]) && (i != mn[i]) && (i != mx[i])) { cout << mn[i] + 1 << " " << i + 1 << " " << mx[i] + 1 << "\n"; return; } } cout << -1 << "\n"; return; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); ll t = 1; 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
def main(): t = int(input()) for i in range(t): n = int(input()) a = [int(x) for x in input().split()] if a[0] + a[1] <= a[-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
import copy import math r = int(input()) for l in range(r): n = int(input()) arr = [int(d) for d in 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
java
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 Solution { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while( t > 0) { int n = scan.nextInt(); long in[] = new long[n]; for(int i = 0; i < n; i++) { in[i] = scan.nextLong(); } if((in[0] + in[1]) <= in[n-1]) { System.out.print("1 2 "+n); } else { System.out.print("-1"); } System.out.println(); t--; } } }
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 badtri(arr): last=arr[-1] for i in range(len(arr)-2): diff=last-arr[i] if arr[i+1]<=diff: return (i+1,i+2,len(arr)) return (-1,) t=int(input()) for i in range(t): n=int(input()) arr=[int(k) for k in input().split()] print(*badtri(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
#!/usr/local/bin/python3 t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int,input().split())) a,b,c=arr[0],arr[1],arr[-1] if a+b>c: print(-1) else: print(1,2,n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def solve(): nb = int(input()) l = list(map(int, input().split())) c = True imi1, mi1 = l.index(min(l))+1, min(l) l.remove(min(l)) imi2, mi2 = l.index(min(l))+2, min(l) l.remove(min(l)) if max(l) >= mi1 + mi2: res = [imi1, imi2, l.index(max(l))+3] res.sort() print(res[0], res[1], res[2]) c = False if c: print(-1) n = int(input()) for _ in range(n): solve()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys inp=sys.stdin.buffer.read().split(b"\n");_ii=-1 def debug(*args): import inspect frame = inspect.currentframe() frame = inspect.getouterframes(frame)[1] string = inspect.getframeinfo(frame[0]).code_context[0].strip() arns = string[string.find('(') + 1:-1].split(',') print(' #debug:',end=' ') for i,j in zip(arns,args): print(i,' = ',j,end=', ') print() def rdln(): global _ii _ii+=1 return inp[_ii] inin=lambda: int(rdln()) inar=lambda: [int(x) for x in rdln().split()] inst=lambda: rdln().strip().decode() _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
# @author import sys class ABadTriangle: def solve(self, tc=0): for _ in range(int(input())): n = int(input()) a = [int(_) for _ in input().split()] u, v, w = a[0], a[1], a[-1] if u + v <= w: print(1, 2, n) else: print(-1) solver = ABadTriangle() input = sys.stdin.readline solver.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
java
import java.util.*; import java.math.*; public class Sample { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int i = 0; i < t; ++i) { int n = input.nextInt(); int[] ls = new int[n]; for(int j = 0; j < n; ++j) { ls[j] = input.nextInt(); } if(ls[0] + ls[1] <= ls[n-1]) { System.out.println("1 2 " + Integer.toString(n)); } else { System.out.println(-1); } } input.close(); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
// package CodeForces; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; public class EducationalRound93A { public static void solve() { int t = s.nextInt(); while(t-- > 0) { int n = s.nextInt(); int[] arr = s.nextIntArray(n); int first = arr[0], second = arr[1], third = arr[n - 1]; if(third >= first + second) { out.println(1 + " " + 2 + " " + (n)); }else { out.println(-1); } } } public static void main(String[] args) { new Thread(null, null, "Thread", 1 << 27) { public void run() { try { out = new PrintWriter(new BufferedOutputStream(System.out)); s = new FastReader(System.in); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } public static PrintWriter out; public static FastReader s; public static class FastReader { private InputStream stream; private byte[] buf = new byte[4096]; private int curChar, snumChars; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (snumChars == -1) { throw new InputMismatchException(); } if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException E) { throw new InputMismatchException(); } } if (snumChars <= 0) { return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int number = 0; do { number *= 10; number += c - '0'; c = read(); } while (!isSpaceChar(c)); return number * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } long sgn = 1; if (c == '-') { sgn = -1; c = read(); } long number = 0; do { number *= 10L; number += (long) (c - '0'); c = read(); } while (!isSpaceChar(c)); return number * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = this.nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = this.nextLong(); } return arr; } 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 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 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; } } }
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; bool cmp(int a, int b) { return a > b; } int main() { int t, n, a, b, c, d; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { if (i == 0) scanf("%d", &a); else if (i == 1) { scanf("%d", &b); } else if (i == (n - 1)) { scanf("%d", &d); } else { scanf("%d", &c); } } if (a + b <= d) printf("1 2 %d\n", n); else printf("-1\n"); } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) c=0 d=0 for i in range(2,n): if(a[0]+a[1]<=a[i]): c=1 d=i break if(c==1): print(1,2,d+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 _ in range(int(input())): N = int(input()) A = list(map(int, input().split())) if A[0] + A[1] <= A[N-1]: print(1, 2, N) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# Bad Triangle t = int(input()) for i in range(0,t): n = int(input()); a = [ ]*n a = [int(x) for x in input().split()] if a[0]+a[1] <= a[len(a)-1]: print(f"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
cases = int(input()) for x in range(cases): input() l = input().split(' ') if len(l) >= 3 and int(l[0]) + int(l[1]) <= int(l[-1]): print('1 2',len(l)) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def main(): for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if(a[-1]>=a[0]+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
for t in range(int(input())): n=int(input()) l=list(map(int,input().split())) if(l[0]+l[1]<=l[-1]): print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python2
# cook your dish here # Name: Rhythem Jain # Date: 01.09.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split()) def msi(): return map(str,input().strip().split()) def li(): return list(mi()) def dmain(): sys.setrecursionlimit(1000000) threading.stack_size(1024000) thread = threading.Thread(target=main) thread.start() #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import log,sqrt,factorial,cos,tan,sin,radians #from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right #from decimal import * #import threading #from itertools import permutations # Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 vow=['a','e','i','o','u','A','E','I','O','U'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[1] def sort2(l):return sorted(l, key=getKey,reverse=True) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def ceil(x,y): if x%y==0: return x//y else: return x//y+1 def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def main(): for _ in range(ii()): num=ii() arr=li() if arr[0]+arr[1]<=arr[-1]: print(1,2,num) else: print(-1) # region fastio # template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read()
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] or a[0]+a[n-1]<=a[1] or a[1]+a[n-1]<=a[0]: print(1,2,n) else: print("-1")
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.Arrays; import java.util.Scanner; import java.lang.Math; public class codeforces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } if(arr[0]+arr[1]<=arr[n-1]){ System.out.println(1+" "+2+" "+(n)); } else{ System.out.println(-1); } } } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
a = int(input()) i = 0 while i < a : b = int(input()) c = input().split(" ") d = [] s = 0 while s < b : d.append(int(c[s])) s = s + 1 s = 0 k = d k.sort() o = 0 l = 0 r = 0 while s < b : if d[s] == k[0] : s = s + 1 o = s break s = s + 1 s = 1 while s < b : if d[s] == k[1] : s = s + 1 l = s break s = s + 1 s = 0 while s < b : if d[s] == k[-1] : s = s + 1 r = s break s = s + 1 if k[0] + k[1] <= k[-1] : print(o,l,r) else: print(-1) i = i + 1
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys T = int(sys.stdin.readline()) for _ in range(T): N = int(sys.stdin.readline()) list_num = list(map(int, sys.stdin.readline().split())) if list_num[-1] >= list_num[0] + list_num[1]: print(1, 2, N) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
for i in range(int(input())): largo = int(input()) lista = [int(j) for j in input().split()] solved = 0 minimo = lista[0] maximo = lista[largo - 1] for x in range(1, largo - 1): if lista[x] + minimo <= maximo: print(1, x + 1, largo) solved = 1 break if solved == 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
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> vc(n); for (int i = 0; i < n; i++) { cin >> vc[i]; } int i; int count = 0; for (i = 0; i < n - 2; i++) { if (vc[i] + vc[i + 1] <= vc[n - 1]) { cout << i + 1 << " " << i + 2 << " " << n << endl; count++; break; } } if (count == 0) cout << -1 << endl; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def A(): n = int(input()) arr = list(map(int, input().split())) x = arr[0] + arr[1] ans = [] if arr[-1] >= x: ans.append(1) ans.append(2) ans.append(n) return ans return ans if __name__ == '__main__': t = int(input()) for i in range(t): ans = A() if not ans: print("-1") else: for i in range(3): print(ans[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
java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.StringTokenizer; public class Learning { public static void main(String[] args) throws Exception { FastInput in = new FastInput(); StringBuilder st = new StringBuilder(); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = in.nextInt(); } int a = arr[0]; int b = arr[1]; int c = arr[n-1]; if(a+b<=c){ st.append(1).append(" ").append(2+" ").append(n); } else st.append(-1); st.append("\n"); } System.out.println(st.toString()); } private static boolean check(int r, int g, int b, int w) { if (r >= 0 && g >= 0 && b >= 0 && w >= 0) { int odd = 0; if (r % 2 == 1) { odd++; } if (g % 2 == 1) { odd++; } if (b % 2 == 1) { odd++; } if (w % 2 == 1) { odd++; } return odd <= 1; } return false; } } class FastInput { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; String next() throws IOException { if (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } Integer nextInt() throws IOException { return Integer.parseInt(next()); } Long nextLong() throws IOException { 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
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): n=int(input()) A=list(map(int,input().split())) if A[0]+A[1]<=A[n-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; void IO() {} int ar[50005]; char ch[50005]; int m, n, k, ii; void solve() { scanf("%d", &n); vector<pair<int, int>> v; for (int i = 1; i <= n; i++) { scanf("%d", &ar[i]); v.push_back({ar[i], i}); } sort(v.begin(), v.end()); if (v[0].first + v[1].first <= v[n - 1].first) { printf("%d %d %d\n", v[0].second, v[1].second, v[n - 1].second); } else printf("-1\n"); } int main() { IO(); int t = 1; scanf("%d", &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
python3
########################################################## from collections import Counter # c=sorted((i,int(val))for i,val in enumerate(input().split())) import heapq # c=sorted((i,int(val))for i,val in enumerate(input().split())) # n = int(input()) # ls = list(map(int, input().split())) # n, k = map(int, input().split()) # n =int(input()) # e=list(map(int, input().split())) from collections import Counter #print("\n".join(ls)) #print(os.path.commonprefix(ls[0:2])) #for _ in range(int(input())): for _ in range(int(input())): n=int(input()) arr = list(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
python3
for _ in range(int(input())): n=int(input()) a =list(map(int,input().split())) x,y,z=a[0],a[1],a[n-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
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n); for (auto &i : v) cin >> i; if (v[0] + v[1] > v[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
t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] a =l[0] b = l[1] c = l[-1] if a+b > c: print(-1) else: print(1, 2, n)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def main(): for _ in range(int(input())): s = int(input()) l = [int(i) for i in input().split()] if l[0] + l[1] > l[-1]: print(-1) else: print(1,2, s) main() #
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range (t): n=int(input()) arr=list(map(int,input().split())) flag=0 for j in range(n-2) : if flag==1: break for k in range (n-1,j+1,-1): if arr[k] >= arr[j]+arr[j+1]: print (j+1,j+2,k+1) flag=1 break if arr[k]< arr[j]+arr[j+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
cpp
#include <bits/stdc++.h> using namespace std; inline int Int() { int x; cin >> x; return x; } inline long long Long() { long long x; cin >> x; return x; } inline float Float() { float x; cin >> x; return x; } inline double Double() { double x; cin >> x; return x; } inline void Yes() { cout << "Yes" << endl; } inline void No() { cout << "No" << endl; } inline void YES() { cout << "YES" << endl; } inline void NO() { cout << "NO" << endl; } const int N = (int)2e5 + 5; const int maxN = (int)1e6 + 6; const long long Mod = (long long)1e9 + 7; const int inf = (int)2e9; const long long Inf = (long long)1e18; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int t, q; cin >> t; for (q = 1; q <= t; q++) { long long n, i, x, c = 0, c1 = 1, c2 = 1, c3 = 1; cin >> n; long long a[n], b[n]; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); for (i = n - 1; i >= 2; i--) { if (b[0] + b[1] <= b[i]) { x = b[i]; c = 1; break; } } if (c) { vector<long long> v; for (i = 0; i < n; i++) { if (v.size() == 3) break; if (b[0] == a[i] and c1) { v.push_back(i + 1); c1 = 0; } else if (b[1] == a[i] and c2) { v.push_back(i + 1); c2 = 0; } else if (x == a[i] and c3) { v.push_back(i + 1); c3 = 0; } } sort(v.begin(), v.end()); for (i = 0; i < 3; i++) cout << v[i] << " "; cout << 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
java
import java.util.Arrays; import java.util.Scanner; /** * * @author DELL */ public class Coding { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here 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(); } int l=0,m=0,k=0; int temp=a[0]+a[1]; boolean f=false; for(int i=2;i<n;i++){ if(a[i]>=temp){ f=true; l=i+1; break; } } if(f){ System.out.println("1"+" "+"2"+" "+l); } 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
''' ___ ___ ___ ___ ___ ___ /\__\ /\ \ _____ /\ \ /\ \ /\ \ /\__\ /:/ _/_ \:\ \ /::\ \ \:\ \ ___ /::\ \ |::\ \ ___ /:/ _/_ /:/ /\ \ \:\ \ /:/\:\ \ \:\ \ /\__\ /:/\:\__\ |:|:\ \ /\__\ /:/ /\ \ /:/ /::\ \ ___ \:\ \ /:/ \:\__\ ___ /::\ \ /:/__/ /:/ /:/ / __|:|\:\ \ /:/ / /:/ /::\ \ /:/_/:/\:\__\ /\ \ \:\__\ /:/__/ \:|__| /\ /:/\:\__\ /::\ \ /:/_/:/__/___ /::::|_\:\__\ /:/__/ /:/_/:/\:\__\ \:\/:/ /:/ / \:\ \ /:/ / \:\ \ /:/ / \:\/:/ \/__/ \/\:\ \__ \:\/:::::/ / \:\~~\ \/__/ /::\ \ \:\/:/ /:/ / \::/ /:/ / \:\ /:/ / \:\ /:/ / \::/__/ ~~\:\/\__\ \::/~~/~~~~ \:\ \ /:/\:\ \ \::/ /:/ / \/_/:/ / \:\/:/ / \:\/:/ / \:\ \ \::/ / \:\~~\ \:\ \ \/__\:\ \ \/_/:/ / /:/ / \::/ / \::/ / \:\__\ /:/ / \:\__\ \:\__\ \:\__\ /:/ / \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ ''' """ β–‘β–‘β–ˆβ–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–ˆ β–‘β–„β–€β–‘β–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–‘β–‘β–ˆβ–‘ β–‘β–ˆβ–‘β–„β–‘β–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–‘β–„β–‘β–ˆβ–‘ β–‘β–ˆβ–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„β–ˆβ–‘ β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ β–„β–ˆβ–€β–ˆβ–€β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–€β–€β–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–‘β–‘β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–‘β–‘β–ˆβ–ˆ β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–€β–‘β–‘β–‘β–‘β–€β–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–„β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–ˆβ–ˆβ–ˆ β–‘β–€β–ˆβ–ˆβ–ˆβ–„β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–„β–ˆβ–ˆβ–ˆβ–€β–‘ β–‘β–‘β–‘β–€β–ˆβ–ˆβ–„β–‘β–€β–ˆβ–ˆβ–€β–‘β–„β–ˆβ–ˆβ–€β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ """ import sys import math import collections import operator as op from collections import deque from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2 from bisect import bisect_right, bisect_left # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') from functools import reduce from sys import stdin, stdout, setrecursionlimit setrecursionlimit(2**20) def factorial(n): if n == 0: return 1 return (n * factorial(n - 1)) def ncr(n, r): r = min(r, n - r) numer = reduce(op.mul, range(n, n - r, -1), 1) denom = reduce(op.mul, range(1, r + 1), 1) return numer // denom # or / in Python 2 def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return (list(factors)) def sumDigits(no): return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10)) MOD = 1000000007 PMOD = 998244353 N = 10**5 T = 1 T = int(stdin.readline()) for _ in range(T): # n, m = list(map(int, stdin.readline().rstrip().split())) n = int(stdin.readline()) a = list(map(int, stdin.readline().rstrip().split())) # b = list(map(int, stdin.readline().rstrip().split())) # a = str(stdin.readline().strip('\n')) # k = int(stdin.readline()) # c = list(map(int, stdin.readline().rstrip().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
from __future__ import division, print_function # import threading # threading.stack_size(2**27) # import sys # sys.setrecursionlimit(10**7) # sys.stdin = open('inpy.txt', 'r') # sys.stdout = open('outpy.txt', 'w') from sys import stdin, stdout import bisect #c++ upperbound import math import heapq i_m=9223372036854775807 def inin(): return int(input()) def stin(): return input() def spin(): return map(int,stin().split()) def lin(): #takes array as input return list(map(int,stin().split())) def matrix(n): #matrix input return [list(map(int,input().split()))for i in range(n)] ################################################ def calculate_sum(a, N): #sum of a to N # Number of multiples m = N / a # sum of first m natural numbers sum = m * (m + 1) / 2 # sum of multiples ans = a * sum return ans def series(N): return (N*(N+1))//2 def count2Dmatrix(i,list): return sum(c.count(i) for c in list) def modinv(n,p): return pow(n,p-2,p) def GCD(x, y): x=abs(x) y=abs(y) if(min(x,y)==0): return max(x,y) while(y): x, y = y, x % y return x def LCM (x, y): return (x * y) // GCD(x, y) def Divisors(n) : l = [] for i in range(1, int(math.sqrt(n) + 1)) : if (n % i == 0) : if (n // i == i) : l.append(i) else : l.append(i) l.append(n//i) return l def isprime(n): for i in range(2, int(math.sqrt(n))+1): if n%i==0: return False return True prime=[] def SieveOfEratosthenes(n): global prime prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 f=[] for p in range(2, n): if prime[p]: f.append(p) return f q=[] def dfs(n,d,v,c): global q v[n]=1 x=d[n] q.append(n) j=c for i in x: if i not in v: f=dfs(i,d,v,c+1) j=max(j,f) # print(f) return j # d = {} for _ in range(inin()): n = inin() a = lin() 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
// Submitted by Subhash Yadav import java.io.*; import java.util.*; public class A { public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int a[]=sc.readArray(n); if(a[0]+a[1]<=a[n-1]) { System.out.println("1 2 "+n); } else System.out.println(-1); } } 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 i in range(int(input())): n = int(input()) arr = [i for i in map(int,input().split())] sorted(arr) if(arr[0]+arr[1]<=arr[n-1]): print(f"1 2 {n}") else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
//package CodeForces; import java.util.Scanner; public class BadTriangle { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { int n=s.nextInt(); int arr[]=new int[n]; boolean done=false; for(int i=0;i<n;i++) { arr[i]=s.nextInt(); } if(arr[0]+arr[1]<=arr[n-1]) { System.out.println(1+" "+2+" "+n); } else { System.out.println(-1); } t--; } } }
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 I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip('\n') RM = readmap = lambda x = int: map(x,readline().split(' ')) #A for _ in range(I()): n,l = I(),[*RM()] if l[0]+l[1] <= l[-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys from sys import stdin import math #Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1)) def iinput(): return int(input()) def minput(): return map(int,input().split()) def linput(): return list(map(int,input().split())) def fiinput(): return int(stdin.readline()) def fminput(): return map(int,stdin.readline().strip().split()) def flinput(): return list(map(int,stdin.readline().strip().split())) for _ in range(iinput()): n=iinput() list1=linput() x=list1[0] y=list1[1] z=list1[-1] if(x+y<=z): 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 solve(n, arr): val = arr[0] + arr[1] for i in range(2, n): if val <= arr[i]: print(1, 2, i+1) return for j in range(n-2): if arr[j] + arr[j+1] <= arr[j+2]: print(j+1, j+2, j+3) return else: continue print(-1) for _ in range(int(input())): n = int(input()) 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
cpp
#include <bits/stdc++.h> using namespace std; void solve() { long long n, i; cin >> n; vector<long long> v(n); for (i = 0; i < n; i++) cin >> v[i]; if (v[0] + v[1] <= v[n - 1]) cout << '1' << " " << '2' << " " << n << "\n"; else cout << "-1" << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long 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
cpp
#include <bits/stdc++.h> using namespace std; long long GCD(long long x, long long y) { if (y == 0) return x; return GCD(y, x % y); } long long LCM(long long x, long long y) { return (x * y) / (GCD(x, y)); } long long LOGK(long long x, long long k) { if (x >= k) return 1 + LOGK(x / k, k); return 0; } long long MPOW(long long a, long long b, long long m) { if (b == 0) return 1; long long x = MPOW(a, b / 2, m); x = (x * x) % m; if (b % 2 == 1) x = (x * a) % m; return x; } long long MINV(long long a, long long m) { return MPOW(a, m - 2, m); } class pnc { long long FACT_MAX, MODU; vector<long long> fact; public: pnc(long long n, long long m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU); } void MFACT_INIT(long long m) { fact[0] = 1; for (long long i = 1; i < FACT_MAX; ++i) fact[i] = (i * fact[i - 1]) % MODU; } long long MFACT(long long n) { return fact[n]; } long long PERM(long long n, long long r) { return (fact[n] * ::MINV(fact[n - r], MODU)) % MODU; } long long COMB(long long n, long long r) { return (PERM(n, r) * ::MINV(fact[r], MODU)) % MODU; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long test = 1; cin >> test; while (test--) { long long n; cin >> n; long long ar[n]; for (long long i = 0; i < n; i++) cin >> ar[i]; if (ar[0] + ar[1] <= ar[n - 1]) { cout << 1 << ' ' << 2 << ' ' << n; cout << "\n"; continue; } if (ar[n - 1] - ar[n - 2] >= ar[0]) { cout << 1 << ' ' << n - 1 << ' ' << n; cout << "\n"; continue; } cout << -1 << "\n"; } }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) res = [] for _ in range(t): n = int(input()) A = list(map(int, input().split())) if A[0] + A[1] <= A[-1]: res.append('{} {} {}'.format(1, 2, n)) else: res.append('-1') print('\n'.join(res))
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.*; import java.text.DecimalFormat; import java.util.*; public class Main { public static int sign(int a){ if(a>0){ return 1; } else if(a<0){ return -1; } else { return 0; } } public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long [] arr=new long[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextLong(); } if(arr[0]+arr[1]>arr[n-1]){ System.out.println(-1); } else{ System.out.println(1+" "+2+" "+n); } } } static class SegmentTree{ int[] arr , sTree; static int N; public SegmentTree(int[] in){ arr=in; N=arr.length-1; sTree=new int[2*N]; build(1,1,N); } public void build(int node, int l, int r){ if(l==r){ sTree[node]=arr[l]; } else{ int leftchild=node*2; int rightchild=node*2+1; int mid =(l+r)/2; build(leftchild,l,mid); build(rightchild,mid+1,r); sTree[node]=sTree[leftchild]&sTree[rightchild]; } } public void update(int i, int val){ int node =i+N-1; arr[i]=val; sTree[node]=val; node=node/2; while(node>0){ int leftchild=node *2; int rightchild=node*2+1; sTree[node]=sTree[leftchild]&sTree[rightchild]; node=node/2; } return; } public int query(int i, int j){ return query(1,1, N, i, j); } public int query(int node,int l, int r, int i , int j){ if(i>r||j<l){ return 1<<30; } if(i<=l&&r<=j){ return sTree[node]; } int leftchild=node*2; int rightchild=node*2+1; int mid =(l+r)/2; return query(leftchild,l,mid,i,j)&query(rightchild,mid+1,r,i,j); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public boolean hasNext() { // TODO Auto-generated method stub return false; } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } }}
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# cook your dish here for _ in range(int(input())): k = int(input()) l = list(map(int,input().split())) a = 0 v = l[0]+l[1] for i in range(2,len(l)): if v<=l[i]: z = i+1 a = 1 break if a == 1: print(1,2,z) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); for (int i = 0; i < T; i++) { int size = scanner.nextInt(); int[] arr = new int[size]; for (int j = 0; j < size; j++) { arr[j] = scanner.nextInt(); } int sum = arr[0] + arr[1]; if (sum <= arr[size - 1]) { System.out.println(1 + " " + 2 + " " + size); } 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
python2
def f(n,a): return ('1 2 %i'%n if a[-1]>=(a[0]+a[1]) else '-1') for t in xrange(int(raw_input())): n=int(raw_input()) a=map(int,raw_input().split()) print f(n,a)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
# -*- coding: utf-8 -*- for i in range(int(input())): n = int(input()) a = list(map(int,input().split())) if a[0]+a[1] <= a[n-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) x, y = a[0], a[1] f = False for i in range(2, n): if x + y <= a[i]: print(1, 2, i + 1) f = True break if not f: 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> int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int a[50005]; for (int x = 0; x < n; x++) { scanf("%d", &a[x]); } if (a[0] + a[1] > a[n - 1]) { printf("-1\n"); } else { printf("1 2 %d\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
java
import java.io.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; /** * @author Utkarsh * */ public class FibinacciSeries { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { 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 Character charAt(int i) { // TODO Auto-generated method stub return null; } public BigInteger nextBigInteger() { // TODO Auto-generated method stub return null; } } // Complete the hurdleRace function below. // public static void solve() { // FastReader s=new FastReader(); int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; // If the element is present at the // middle itself if (arr[mid] == x) return mid; // If element is smaller than mid, then // it can only be present in left subarray if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); // Else the element can only be present // in right subarray return binarySearch(arr, mid + 1, r, x); } // We reach here when element is not present // in array return -1; } static // Driver method to test above // Java implementation of iterative Binary Search // Returns index of x if it is present in arr[], // else return -1 int lowerBound(int[] a,int n,int key){ int s =0,e=n-1; int ans = -1; while(s<=e){ int mid = (s+e)/2; if(a[mid]==key){ ans = mid; e = mid - 1; } else if(a[mid]>key){ e = mid - 1; } else{ s = mid + 1; } } return ans; } static int count(String se,char c,int l,int r) { if(l==r) { if(se.charAt(l)==c)return 0; else return 1; } int mid = (l+r)/2; int c1=0,c2=0; for(int i=l;i<=mid;i++) { if(se.charAt(i)!=c)c1++; } for(int i=r;i>mid;i--) { if(se.charAt(i)!=c)c2++; } int y = count(se,(char)((int)c+1),mid+1,r); int x = count(se,(char)((int)c+1),l,mid); return Math.min(c1+y, c2+x); } public static double log2(long N) { // calculate log2 N indirectly // using log() method double result = (double)(Math.log(N) / Math.log(2)); return result; } static boolean sign(long n) { return n>0; } public static int solve(long[] ar,int n) { long sum=0; for(int i=0;i<n;i++) { sum+=ar[i]; if(sum<=0)return 0; } sum=0; for(int i=n-1;i>=0;i--) { sum+=ar[i]; if(sum<=0)return 0; } return 1; } public static void main(String[] args) throws IOException { FastReader s=new FastReader(); int t = s.nextInt(); while(t-->0) { int n = s.nextInt(); long[] ar = new long[n]; for(int i=0;i<n;i++) { ar[i] = s.nextInt(); } int flag=0; for(int i=n-1;i>=2 && flag==0;i--) { if((ar[0]+ar[1])<=ar[i]) { System.out.println((1)+" "+(2)+" "+(i+1)); flag=1; } } if(flag==0)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
import sys import heapq, functools, collections import math, random from collections import Counter, defaultdict # available on Google, not available on Codeforces # import numpy as np # import scipy def solve(lst): # fix inputs here console("----- solving ------") lst = sorted(lst) if lst[0] + lst[1] > lst[-1]: return -1 else: return "{} {} {}".format(1, 2, len(lst)) def console(*args): # the judge will not read these print statement print('\033[36m', *args, '\033[0m', file=sys.stderr) return # fast read all # sys.stdin.readlines() for case_num in range(int(input())): # read line as a string # strr = input() # read line as an integer _ = int(input()) # read one line and parse each word as a string # lst = input().split() # read one line and parse each word as an integer lst = list(map(int,input().split())) # read matrix and parse as integers (after reading read nrows) # lst = list(map(int,input().split())) # nrows = lst[0] # index containing information, please change # grid = [] # for _ in range(nrows): # grid.append(list(map(int,input().split()))) res = solve(lst) # please change # Google - case number required # print("Case #{}: {}".format(case_num+1, res)) # Codeforces - no case number required print(res)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) if(l[-1]<l[0]+l[1]): print("-1\n") else: print("1 2",n,'\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
#!/usr/bin/env python3 ''' Author: andyli Time: 2020-08-14 22:35:30 ''' import os from io import BytesIO, IOBase import sys 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) else: print(1,2,n) return # region fastio BUFSIZE = 1048576 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda: self.buffer.read().decode('ascii') self.readline = lambda: self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) def input(): return sys.stdin.readline().rstrip('\r\n') # endregion 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
cpp
#include <bits/stdc++.h> using namespace std; int n; const int N = 5e4 + 10; int a[N]; void solve() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; cout << (a[0] + a[1] > a[n - 1] ? "-1" : "1 2 " + to_string(n)) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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
python3
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a[0] y=a[1] c=0 k=0 for i in range(2,n): if x+y<=a[i]: c=0 k=i break else: c=c+1 if c==0: print(1,2,k+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 tt in range(int(input())): n = int(input()) a = [int(_) for _ in input().split()] if a[0] + a[1] <= a[n-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
def triangle(a): j=len(a)//2 for i in range(len(arr)): while(j<len(arr)): if a[i]+a[i+1]<=a[j]: print(i+1,i+2,j+1) return j+=1 print(-1) n=int(input()) for i in range(n): m=int(input()) arr=[0]*m arr=list(map(int,input().split())) triangle(arr)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) a = arr[0] b = arr[1] flag = False for i in range(2, n): if (a + b) <= arr[i]: print(1, 2, i + 1) flag = True break if flag is 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
from sys import stdin, stdout from collections import Counter,deque import math input = stdin.readline print = stdout.write def inpn(): return(int(input())) def inpl(): return(list(map(int,input().split()))) def inps(): return input() def invr(): return (map(int, input().split())) def outs(s): print(s) def outn(n): print(str(n)) def outl(l): for i in l: print(str(i)) for _ in range(int(input())): n = inpn() l=inpl() def bin_search(data, target): # order of log(n) # works only on sorted list low = 0 high = len(data) - 1 while low <= high: mid = (low + high) // 2 if data[mid] >= target: return mid elif data[mid] < target: low = mid + 1 else: high = mid - 1 return -1 for i in range(n - 2): a = bin_search(l, l[i] + l[i + 1]) if a != -1: outn(i + 1) print(" ") outn(i+2) print(" ") outn(a+1) print("\n") break else: outn(-1) print("\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()) a=list(map(int,input().split()));a.sort() k=a[0]+a[1];c=0 for i in range(2,n): if a[i]>=k: b=i;c=1 break if c==0: print(-1) else: print(1,2,b+1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.io.*; import java.util.*; import java.lang.*; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new BufferedOutputStream(System.out)); int T = in.nextInt(); for(int test=0;test<T;test++){ int n = in.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i]=in.nextInt(); } if(a[0]+a[1]<=a[n-1]){ out.println(1+" "+2+" "+n); } else { out.println(-1); } } out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
test = int(input()) for _ in range(test): n = int(input()) arr = list(map(int, input().split())) t = arr[0]+arr[1] o = arr[-1] if t<=o: 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 k in range(t): n=int(input()) flag=0 a= list(map(int,input().split())) temp=a[0]+a[1] if(a[n-1]>=temp): 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
python2
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def fi(): return float(input()) def si(): return input() def msi(): return map(str,input().split()) def mi(): return map(int,input().split()) def li(): return list(mi()) def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return (x*y)//(gcd(x,y)) mod=1000000007 def modInverse(b,m): g = gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def modu(a,b,m): a = a % m inv = modInverse(b,m) if(inv == -1): return -999999999 else: return (inv*a)%m from math import log,sqrt,factorial,cos,tan,sin,radians,ceil,floor import bisect from decimal import * getcontext().prec = 25 abc="abcdefghijklmnopqrstuvwxyz" pi=3.141592653589793238 def main(): for _ in range(ii()): n=ii() a=li() if a[0]+a[1]<=a[n-1]: print(1,2,n) else: print(-1) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main()
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) i = 0 j = 1 k = 2 breaked = False while i < n and j < n: if a[i] + a[j] <= a[k]: print(i+1, j+1, k+1) breaked = True break if k < n-1: k += 1 elif j < n-2: j += 1 else: i += 1 if not breaked: 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()) arr = list(map(int, input().split())) a, b, c = arr[0], arr[1], arr[-1] if a+b <= c: print(1, 2, n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
java
import java.util.*; import java.io.*; public class Bad_trianlge { 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) { // TODO Auto-generated method stub FastReader t = new FastReader(); PrintWriter o = new PrintWriter(System.out); int test = t.nextInt(); while (test-- > 0) { int n = t.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = t.nextInt(); } if (a[0] + a[1] <= a[n - 1]) { o.println("1 2 " + n); } else o.println("-1"); } o.flush(); o.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
python3
import sys input = sys.stdin.readline from collections import * for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) x, y, z = a[0], a[1], a[-1] if z>=x+y: 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()) b = list(map(int, input().split())) ans = False for i in range(2, len(b)): if b[0]+b[1] <= b[i]: ans = True print(1, 2, i+1) break if ans == 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
# -*- coding: utf-8 -*- """ Created on Mon Aug 3 21:10:40 2020 @author: dennis """ import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) for case in range(int(input())): 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
# cook your dish here t = int(input()) while t: n = int(input()) l = list(map(int,input().split())) i = 0 j = 1 count = 0 for k in range(2,n): if (l[k])>=(l[i]+l[j]): print(f'{i+1} {j+1} {k+1}') count = 1 break if count ==0: 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
java
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t-->0){ int n=scn.nextInt(); long [] arr=new long[n]; for(int i=0;i<arr.length;i++){ arr[i]=scn.nextLong(); } if(arr[0] + arr[1] <=arr[arr.length-1]){ System.out.println(1 + " " + 2 + " " + arr.length); } 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())) arr.sort() 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
python3
#_______________________________________________________________# def fact(x): if x == 0: return 1 else: return x * fact(x-1) def lower_bound(li, num): #return 0 if all are greater or equal to answer = len(li)-1 start = 0 end = len(li)-1 while(start <= end): middle = (end+start)//2 if li[middle] >= num: answer = middle end = middle - 1 else: start = middle + 1 return answer #index where x is not less than num def upper_bound(li, num): #return n-1 if all are small or equal answer = -1 start = 0 end = len(li)-1 while(start <= end): middle = (end+start)//2 if li[middle] <= num: answer = middle start = middle + 1 else: end = middle - 1 return answer #index where x is not greater than num def abs(x): return x if x >=0 else -x def binary_search(li, val, lb, ub): # ITS A BINARY ans = 0 while(lb <= ub): mid = (lb+ub)//2 #print(mid, li[mid]) if li[mid] > val: ub = mid-1 elif val > li[mid]: lb = mid + 1 else: ans = 1 break return ans def sieve_of_eratosthenes(n): ans = [] arr = [1]*(n+1) arr[0],arr[1], i = 0, 0, 2 while(i*i <= n): if arr[i] == 1: j = i+i while(j <= n): arr[j] = 0 j += i i += 1 for k in range(n): if arr[k] == 1: ans.append(k) return ans def nc2(x): if x == 1: return 0 else: return x*(x-1)//2 def kadane(x): #maximum subarray sum sum_so_far = 0 current_sum = 0 for i in x: current_sum += i if current_sum < 0: current_sum = 0 else: sum_so_far = max(sum_so_far,current_sum) return sum_so_far def mex(li): check = [0]*1001 for i in li: check[i] += 1 for i in range(len(check)): if check[i] == 0: return i def sumdigits(n): ans = 0 while(n!=0): ans += n%10 n //= 10 return ans def product(li): ans = 1 for i in li: ans *= i return ans def maxpower(n,k): cnt = 0 while(n>1): cnt += 1 n //= k return cnt def knapsack(li,sumi,s,n,dp): if s == sumi//2: return 1 elif n==0: return 0 else: if dp[n][s] != -1: return dp[n][s] else: if li[n-1] <= s: dp[n][s] = knapsack(li,sumi,s-li[n-1],n-1,dp) or knapsack(li,sumi,s,n-1,dp) else: dp[n][s] = knapsack(li,sumi,s,n-1,dp) return dp[n][s] def pref(li): pref_sum = [0] for i in li: pref_sum.append(pref_sum[-1] + i) return pref_sum #_______________________________________________________________# ''' β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–€β–€β–€β–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–„ β–‘β–β–ˆβ–ˆβ–ˆβ–ˆβ–€β–’β–’Aestroixβ–’β–’β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–‘β–ˆβ–ˆβ–ˆβ–€β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–€β–ˆβ–ˆβ–ˆβ–ˆ β–‘β–β–ˆβ–ˆβ–’β–’β–’β–’β–’KARMANYAβ–’β–’β–’β–’β–’β–’β–ˆβ–ˆβ–ˆβ–ˆβ–Œ ________________ β–‘β–β–ˆβ–Œβ–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–ˆβ–ˆβ–ˆβ–ˆβ–Œ ? ? |β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’| β–‘β–‘β–ˆβ–’β–’β–„β–€β–€β–€β–€β–€β–„β–’β–’β–„β–€β–€β–€β–€β–€β–„β–’β–’β–β–ˆβ–ˆβ–ˆβ–Œ ? |___CM ONE DAY___| β–‘β–‘β–‘β–β–‘β–‘β–‘β–„β–„β–‘β–‘β–Œβ–β–‘β–‘β–‘β–„β–„β–‘β–‘β–Œβ–’β–β–ˆβ–ˆβ–ˆβ–Œ ? ? |β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’| β–‘β–„β–€β–Œβ–‘β–‘β–‘β–€β–€β–‘β–‘β–Œβ–β–‘β–‘β–‘β–€β–€β–‘β–‘β–Œβ–’β–€β–’β–ˆβ–Œ ? ? β–‘β–Œβ–’β–€β–„β–‘β–‘β–‘β–‘β–„β–€β–’β–’β–€β–„β–‘β–‘β–‘β–„β–€β–’β–’β–„β–€β–’β–Œ ? β–‘β–€β–„β–β–’β–€β–€β–€β–€β–’β–’β–’β–’β–’β–’β–€β–€β–€β–’β–’β–’β–’β–’β–’β–ˆ ? ? β–‘β–‘β–‘β–€β–Œβ–’β–„β–ˆβ–ˆβ–„β–„β–„β–„β–ˆβ–ˆβ–ˆβ–ˆβ–„β–’β–’β–’β–’β–ˆβ–€ ? β–‘β–‘β–‘β–‘β–„β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆ=========β–ˆβ–’β–’β–β–Œ β–‘β–‘β–‘β–€β–ˆβ–ˆβ–ˆβ–€β–€β–ˆβ–ˆβ–ˆβ–ˆβ–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–€β–’β–Œ β–‘β–‘β–‘β–‘β–‘β–Œβ–’β–’β–’β–„β–’β–’β–’β–„β–’β–’β–’β–’β–’β–’β– β–‘β–‘β–‘β–‘β–‘β–Œβ–’β–’β–’β–’β–€β–€β–€β–’β–’β–’β–’β–’β–’β–’β– β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ ''' from math import * for _ in range(int(input())): #for _ in range(1): n = int(input()) #n,m,sx,sy = map(int,input().split()) #s = input() #s2 = input() #r, g, b, w = map(int,input().split()) a = list(map(int,input().split())) #b = list(map(int,input().split())) #s1 = list(st) #a = [int(x) for x in list(s1)] #b = [int(x) for x in list(s2)] f = 0 ans = lower_bound(a,a[0]+a[1]) if a[ans] < a[0]+a[1]: print(-1) else: print(1,2,ans+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()) 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()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) s=arr[0]+arr[1] f=0 th=0 for i in range(2,n): if s > arr[i]: continue else: f=1 th=i if f==1: print("1 2",end=" ") print(th+1) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int size; cin >> size; std::vector<int> v(size); for (auto& x : v) cin >> x; if (v[0] + v[1] > v[size - 1]) cout << -1 << endl; else cout << 1 << " " << 2 << " " << size << endl; } return 0; }
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) if l[0]+l[1]<=l[n-1]: print(1,2,n) else: print(-1)
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
import sys import math input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) if a[0] + a[1] <= a[n-1]: print(1, 2, n) else: print('-1')
1398_A. Bad Triangle
You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i ≀ a_{i + 1}). Find three indices i, j, k such that 1 ≀ i < j < k ≀ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it. Input The first line contains one integer t (1 ≀ t ≀ 1000) β€” the number of test cases. The first line of each test case contains one integer n (3 ≀ n ≀ 5 β‹… 10^4) β€” the length of the array a. The second line of each test case contains n integers a_1, a_2, ... , a_n (1 ≀ a_i ≀ 10^9; a_{i - 1} ≀ a_i) β€” the array a. It is guaranteed that the sum of n over all test cases does not exceed 10^5. Output For each test case print the answer to it in one line. If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them. Otherwise, print -1. Example Input 3 7 4 6 11 11 15 18 20 4 10 10 10 11 3 1 1 1000000000 Output 2 3 6 -1 1 2 3 Note In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer. In the second test case you always can construct a non-degenerate triangle.
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n" ], "output": [ "1 2 7\n-1\n1 2 3\n" ] }
{ "input": [ "3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n", "1\n6\n1 1 1 2 2 3\n", "1\n3\n21 78868 80000\n", "1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n", "1\n3\n78788 78788 157577\n", "1\n3\n5623 5624 10000000\n", "1\n10\n1 7 7 7 7 9 9 9 9 9\n", "1\n3\n5739271 5739272 20000000\n", "1\n3\n1 65535 10000000\n", "1\n3\n78788 78788 100000\n", "1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n" ], "output": [ "1 2 7\n-1\n1 2 3\n", "1 2 6\n", "1 2 3\n", "1 2 14\n", "1 2 3\n", "1 2 3\n", "1 2 10\n", "1 2 3\n", "1 2 3\n", "-1\n", "1 2 15\n" ] }
CORRECT
python3
t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) if(a[n-1]>=a[0]+a[1]): print(1,2,n) else: print(-1)