Educational Codeforces Round 93 (Rated for Div. 2) 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 non-degenerate 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
Copy

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

Output
Copy

2 3 6
-1
1 2 3

Note

In the first test case it is impossible with sides 6
, 11 and 18

. Note, that this is not the only correct answer.

In the second test case you always can construct a non-degenerate triangle.


题意 : 给定一个递增序列,如果这个序列选三个数不能构成三角形,就输出这三个数的位置(任意3个满足的数都可以),如果任选3个数都可以构成三角形就输出-1

  • 因为有序,所以我们选择第arr[1],arr[2]最后一个arr[n]组三角形,
    如果可以构成三角形,则其他任意选3个都可以构成三角形,直接输出-1
  • 如果arr[1],arr[2]和arr[n]不能构成三角形,就输出他们啦1 2 n
 read(Q);
 while(Q--) {
     read(n);
     for(int i=1; i<=n; i++) read(a[i]);
     if(a[1]+a[2] > a[n]) printf("-1\n");
     else {
         printf("1 2 %d\n", n);
     }
 }
// #define debug
#ifdef debug
#include <time.h>
#endif
 
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
 
#define MAXN ((int)1e5+7)
#define ll long long int
#define INF (0x7f7f7f7f)
#define fori(lef, rig) for(int i=lef; i<=rig; i++)
#define forj(lef, rig) for(int j=lef; j<=rig; j++)
#define fork(lef, rig) for(int k=lef; k<=rig; k++)
#define QAQ (0)
 
using namespace std;
 
#define show(x...) \
    do { \
       cout << "\033[31;1m " << #x << " -> "; \
       err(x); \
    } while (0)
 
void err() { cout << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
 
namespace FastIO{
 
    char print_f[105];
    void read() {}
    void print() { putchar('\n'); }
 
    template <typename T, typename... T2>
       inline void read(T &x, T2 &... oth) {
           x = 0;
           char ch = getchar();
           ll f = 1;
           while (!isdigit(ch)) {
               if (ch == '-') f *= -1; 
               ch = getchar();
           }
           while (isdigit(ch)) {
               x = x * 10 + ch - 48;
               ch = getchar();
           }
           x *= f;
           read(oth...);
       }
    template <typename T, typename... T2>
       inline void print(T x, T2... oth) {
           ll p3=-1;
           if(x<0) putchar('-'), x=-x;
           do{
                print_f[++p3] = x%10 + 48;
           } while(x/=10);
           while(p3>=0) putchar(print_f[p3--]);
           putchar(' ');
           print(oth...);
       }
} // namespace FastIO
using FastIO::print;
using FastIO::read;
 
int n, m, Q, K, a[MAXN];
 
signed main() {
#ifdef debug
    freopen("test.txt", "r", stdin);
    clock_t stime = clock();
#endif
    read(Q);
    while(Q--) {
        read(n);
        for(int i=1; i<=n; i++) read(a[i]);
        if(a[1]+a[2] > a[n]) printf("-1\n");
        else {
            printf("1 2 %d\n", n);
        }
    }
 
 
 
 
 
#ifdef debug
   clock_t etime = clock();
   printf("rum time: %lf 秒\n",(double) (etime-stime)/CLOCKS_PER_SEC);
#endif 
   return 0;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值