120 lines
2.4 KiB
Java
120 lines
2.4 KiB
Java
package chelper;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Comparator;
|
|
|
|
import io.InputReader;
|
|
import io.OutputWriter;
|
|
import misc.SimpleSavingChelperSolution;
|
|
|
|
|
|
public class D extends SimpleSavingChelperSolution {
|
|
|
|
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
|
wrapSolve(testNumber, in, out);
|
|
}
|
|
|
|
class Pair implements Comparable<Pair> {
|
|
|
|
public final long first;
|
|
public final int second;
|
|
|
|
public Pair(long first, int second) {
|
|
this.first = first;
|
|
this.second = second;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(Pair o) {
|
|
return Long.compare(first, o.first);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void solve(int testNumber) {
|
|
int n = in.nextInt();
|
|
int q = in.nextInt();
|
|
|
|
long[] allVal = new long[n];
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
allVal[i] = in.nextLong();
|
|
}
|
|
|
|
int[][] requests = new int[q][3];
|
|
int[][] answers = new int[q][3];
|
|
|
|
for (int i = 0; i < q; i++) {
|
|
requests[i][0] = in.nextInt() - 1;
|
|
requests[i][1] = in.nextInt();
|
|
requests[i][2] = i;
|
|
}
|
|
|
|
Arrays.sort(requests, Comparator.comparingInt(o -> o[0]));
|
|
|
|
int N = 110;
|
|
|
|
long[] set;
|
|
|
|
for (int[] i : requests) {
|
|
int l = i[0];
|
|
int r = i[1];
|
|
|
|
int m = Math.min(N, r - l);
|
|
|
|
set = Arrays.copyOfRange(allVal, l, l + m);
|
|
Arrays.sort(set);
|
|
|
|
boolean ok = false;
|
|
|
|
long a1 = -1;
|
|
int b1 = -1;
|
|
long a2 = -1;
|
|
int b2 = -1;
|
|
long a3 = -1;
|
|
int b3 = -1;
|
|
|
|
for (int j = 0; j < m - 2; j++) {
|
|
if (set[j] + set[j + 1] > set[j + 2]) {
|
|
ok = true;
|
|
a1 = set[j];
|
|
a2 = set[j + 1];
|
|
a3 = set[j + 2];
|
|
|
|
break;
|
|
}
|
|
}
|
|
if (ok) {
|
|
for (int j = 0; j < m && (b1 == -1 || b2 == -1 || b3 == -1); j++) {
|
|
if (allVal[l + j] == a1 && b1 == -1) {
|
|
b1 = l + j + 1;
|
|
continue;
|
|
}
|
|
|
|
if (allVal[l + j] == a2 && b2 == -1) {
|
|
b2 = l + j + 1;
|
|
continue;
|
|
}
|
|
|
|
if (allVal[l + j] == a3 && b3 == -1) {
|
|
b3 = l + j + 1;
|
|
}
|
|
}
|
|
|
|
answers[i[2]][0] = b1;
|
|
answers[i[2]][1] = b2;
|
|
answers[i[2]][2] = b3;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < q; i++) {
|
|
if (answers[i][0] == 0) {
|
|
out.println(-1);
|
|
} else {
|
|
out.println(answers[i][0] + " " + answers[i][1] + " " + answers[i][2]);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|