We need to solve: given array a of length n, find any nonempty subarray (contiguous) such that max(subarray) - min(subarray) >= length(subarray). Or output NO if none.
Constraints: t up to 10k, sum n <= 2e5. So O(n) or O(n log n) per test.
We need to answer existence and produce an example.
Observation: For any subarray, length = r-l+1. Condition: max-min >= length.
We can think about looking for subarrays of length at least 2 (since length 1: max-min=0<1 always, so length must be >=2, but maybe length 1 can't satisfy, so we need at least length 2). So we can ignore length 1.
Goal: find any subarray where condition holds. Could be whole array.
Simplify: For a subarray of length L, we need max-min >= L.
Observation: If there exists any pair of adjacent elements where absolute difference >= 2, then subarray of length 2 will satisfy? For length 2, condition max-min >= 2. So if adjacent pair differ by at least 2, then subarray of those two satisfies. Similarly, if adjacent elements differ by exactly 1, then max-min=1 < 2, so not enough. So for length 2, need |a[i]-a[i+1]| >= 2.
Thus a simple solution: if any adjacent pair has difference >= 2, output that pair.
But what if no adjacent pair has difference >= 2? That means the array is "smooth": all consecutive differences are 0 or 1 (since numbers are integers, difference 0 or 1). Actually difference could be 0 or 1 only. Because difference of 0 means equal; difference of 1 means either increase by 1 or decrease by 1. Could be negative? Actually absolute difference. So condition: for all i, |a[i+1]-a[i]| <= 1.
Now, can there be interesting subarray of longer length when all adjacent differences <= 1? We need to check.
If the array is monotonic or has some variation, max-min can increase as length grows, but since adjacent steps are at most 1, over length L, the maximum possible range (max-min) is at most L-1 (by walking from min to max). Actually if you start at a value, and each step you can change by at most 1, then after L-1 steps (for length L subarray), the value can change at most L-1 in absolute terms. So max-min <= L-1. So condition max-min >= L would require max-min >= L, but max-min <= L-1. So impossible. Therefore if all adjacent differences are <= 1, there is no interesting subarray at all.
Wait, is that always true? Let's think: For a subarray of length L, the elements are a[l], a[l+1], ..., a[r]. Adjacent differences are bounded: |a[i+1]-a[i]| <= 1 for all i from l to r-1. So the total variation from min to max cannot exceed L-1. More formally: Consider any two indices i<j within the subarray. The difference a[j]-a[i] can be expressed as sum of differences over path, each step at most 1 in magnitude, so |a[j]-a[i]| <= j-i <= L-1. So max-min <= L-1. So condition max-min >= L cannot hold. So indeed no interesting subarray.
But what about non-adjacent pairs? The bound on difference between any two positions is at most distance. So no.
Thus the necessary and sufficient condition for existence of an interesting subarray is: there exists an adjacent pair with absolute difference >= 2. Because if such pair exists, that's a valid subarray of length 2. If not, no subarray exists.
But is that always sufficient? Check: length 2 subarray needs max-min >= 2. If adjacent diff >= 2, then yes. So we have a valid subarray.
But wait, what if there exists an interesting subarray of length > 2 but no adjacent pair with diff >= 2? Could such exist? As argued, if all adjacent diffs <= 1, then for any subarray, max-min <= length-1, so cannot be >= length. So no.
Thus the problem reduces to: check if there exists i such that |a[i]-a[i+1]| >= 2. If yes, output i and i+1 (as l, r). If not, output NO.
But hold on: is it possible that adjacent diff >=2 but the subarray of length 2 is not interesting because max-min >=2? Actually if diff >=2, then max-min = that diff, which is >=2, so length 2 condition satisfied. So yes.
Thus solution is trivial: scan array, check consecutive differences.
But wait, example: Input: 5: 1 2 3 4 5. Adjacent diffs are 1,1,1,1 (all 1). So no interesting subarray => output NO. That matches example.
Second: 4: 2 0 1 9. Adjacent diffs: |2-0|=2 >=2, so we output 1 2? But example output is "YES" and "1 4". They chose the whole array. But our approach would output 1 2. That is also valid because any answer is accepted. The problem says "If there are multiple answers, print any." So outputting 1 2 is fine. So our solution works.
Third: 2: 2019 2020: diff=1, so NO. matches.
So it's that simple? Let's double-check the logic: Could there be a scenario where there is no adjacent diff >=2 but still an interesting subarray? Suppose array: [0,2,0]. Adjacent diffs: |0-2|=2 >=2 => so there is. So okay.
What about array: [0,1,0,1,0,...]. All diffs 1. Then max-min for any subarray? Consider length 3: maybe max=1, min=0 => diff=1 < 3. So no.
What about array where some non-consecutive difference is large, but adjacent diffs are all <=1? Is that possible? For non-consecutive difference to be large, say a[i] and a[j] differ by 10, then along the path, the differences accumulate. Since each step max change is 1, you need at least 10 steps. So j-i >= 10. But then max-min <= j-i <= length-1? Actually if j-i = 10, then length L = j-i+1 = 11, and max-min <= 10. So max-min >= 11 is impossible. So condition max-min >= L can't hold. So indeed impossible.
But wait, condition is max-min >= length, not >. So equality to length would be sufficient. For length L, we need max-min >= L. With max-min <= L-1, it's impossible. So correct.
Thus solution is straightforward.
But before finalizing, check edge cases: n=2. If diff>=2 => YES (print 1 2). If diff=1 or 0 => NO. That's fine.
Constraints: t up to 10k, sum n <= 2e5, O(n) per test total O(total n) works.
Implementation: For each test case: read n, read list a. Iterate i from 0 to n-2, check if abs(a[i]-a[i+1]) >= 2. If found, output YES and i+1, i+2 (1-indexed). Else output NO.
That's it.
But wait, is there any scenario where we need to output a subarray longer than 2? The problem says "If there are multiple answers, print any." So it's fine. So we are done.
But hold on: Let's verify with another example. Suppose array: [5, 5, 5, 5]. All diffs=0, so NO. Indeed for any subarray, max-min=0, length>=2 => 0< length => no interesting. So NO.
Suppose array: [5, 5, 6, 5, 5]. Adjacent diffs: 0,1,1,0. No diff >=2 -> NO. Check any subarray: maybe [5,6,5] length 3, max-min=1<3. So NO.
Suppose array: [0, 2, 2, 2]. Adjacent diff: |0-2|=2 -> YES. So output 1 2.
Thus solution.
But note: The problem statement says "nonempty subarray" and length >=2 are the only candidates. So it's fine.
However, I recall that there is a known Codeforces problem "Interesting Subarray" (maybe problem 1270B?) Actually there is problem "Interesting Subarray" from Codeforces Round #... That problem had exactly this condition and the solution was indeed to find an adjacent pair with difference >=2. Yes, it's a known problem: CF 1270B? Let's check: I think it's from Codeforces Round #... But yes, solution is as described.
Thus final answer.
But wait, there is nuance: The condition max-min >= length. For length 2, need difference >=2. But if difference >=2, it's good. But what if the difference is negative? Actually absolute value. So check absolute difference.
Implementation details: For each test case, we need to output "YES" and then l r if found. Or "NO". Use sys.stdin, sys.stdout.
But caution: input size large, use fast I/O.
Edge case: n may be 1? Actually constraints say n >= 2: "2 ≤ n ≤ 2⋅10^5". So at least 2. So okay.
Now produce final answer.
But we need to be careful: The sum of n over all test cases is up to 2e5, so scanning all is fine.
Thus code:
import sys
def solve():
data = sys.stdin.read().strip().split()
it = iter(data)
t = int(next(it))
out_lines = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
found = False
for i in range(n-1):
if abs(a[i] - a[i+1]) >= 2:
out_lines.append("YES")
out_lines.append(f"{i+1} {i+2}")
found = True
break
if not found:
out_lines.append("NO")
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()
Yes.
But wait, is there any scenario where the adjacent pair diff >=2 but the indices are not in order? Actually we output the pair itself.
Thus answer.
But let me double-check the initial problem statement: "For an array a of integers let's denote its maximal element as max(a), and minimal as min(a). We will call an array a of k integers interesting if max(a) - min(a) ≥ k." That is exactly. So for subarray of length 2, condition is diff >=2.
Thus indeed it's trivial.
But there might be nuance: The array is of integers, but we are not asked to find minimal subarray, just any. So adjacent pair works.
Now test with sample input:
3
5
1 2 3 4 5
4
2 0 1 9
2
2019 2020
Our code: t=3.
First: n=5, a=1 2 3 4 5. Differences: 1,1,1,1 -> none >=2 => NO.
Second: n=4, a=2 0 1 9. Differences: |2-0|=2 -> >=2 => YES, output 1 2. That's valid alternative.
Third: n=2, a=2019 2020 diff=1 -> NO.
Output would be:
NO
YES
1 2
NO
But sample output had YES and 1 4. Our output is also correct because any answer is allowed.
Thus solution passes.
Now produce final message with explanation.
But maybe we should discuss why it's sufficient: If there is no such adjacent pair, then for any i<j, |a[i]-a[j]| <= j-i. So max-min <= length-1, thus condition fails.
That's it.
Now answer. ```python
import sys
def solve() -> None:
data = sys.stdin.buffer.read().split()
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
found = False
for i in range(n - 1):
if abs(a[i] - a[i + 1]) >= 2:
out.append("YES")
out.append(f"{i + 1} {i + 2}")
found = True
break
if not found:
out.append("NO")
sys.stdout.write("\n".join(out))
if name == "main":
solve()