A. Bad Triangle

传送门

A. Bad Triangle

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a1,a2,…,an, which is sorted in non-decreasing order (ai≤ai+1)Find three indices i, j, k such that 1≤i<j<k≤n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to ai, aj and ak (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it.

Input
The first line contains one integer t(1≤t≤1000) — the number of test cases.
The first line of each test case contains one integer n(3≤n≤5⋅104) — the length of the array a The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109; ai−1≤ai) — the array a It is guaranteed that the sum of n over all test cases does not exceed 105

Output
For each test case print the answer to it in one line.If there is a triple of indices i, j, k (i<j<k) such that it is impossible to construct a nondegenerate triangle having sides equal to ai, aj and ak, print that three indices in ascending order. If there are multiple answers, print any of them.
Otherwise, print -1.

Example
Input

3
7
4 6 11 11 15 18 20
4
10 10 10 11
3
1 1 1000000000

Output

2 3 6
-1
1 2 3

Note
In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer.In the second test case you always can construct a non-degenerate triangle.

题意:判断能否构成三角形,能则输出-1,不能则输出任意三组不能构成的数字的下标。

思路:用特征值判断,因为是按升序输入,所以判断两组特解即可,可以是1,2,n;或者1,n-1,n;判断条件(a+b<=c||a+c<=b||c+b<=a);
或者只判断输出-1的情况,满足(a+b>c),其他情况均输出1,2,n;

AC代码
1

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
const int maxn=100000;
using namespace std;
int main()
{
    long long  t,n;
   long long a[maxn];
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
               cin>>a[i];
            if(a[1]+a[2]<=a[n]||a[2]+a[n]<=a[1]||a[n]+a[1]<=a[2])
               {
                   cout<<1<<' '<<2<<' '<<n<<endl;}
            else if(a[1]+a[n-1]<=a[n]||a[1]+a[n]<=a[n-1]||a[n-1]+a[n]<=a[1])
                {cout<<1<<' '<<n-1<<' '<<n<<endl;}
            else{cout<<-1<<endl;}
    }return 0;
}

AC代码
2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll a[maxn];
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
		int n;
		scanf("%d",&n);
		for(int i= 1;i<=n;++i)
        scanf("%lld",&a[i]);
        /*cin>>a[i]*/
		if(a[1]+a[2]>a[n])
        cout<<-1<<endl;
		else
		cout<<1<<' '<<2<<' '<<n<<endl;
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值