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;
}