Codeforces 1270B 灵感题

B. Interesting Subarray
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

For an array aa of integers let's denote its maximal element as max(a)max(a), and minimal as min(a)min(a). We will call an array aa of kk integers interesting if max(a)min(a)kmax(a)−min(a)≥k. For example, array [1,3,4,3][1,3,4,3] isn't interesting as max(a)min(a)=41=3<4max(a)−min(a)=4−1=3<4 while array [7,3,0,4,3][7,3,0,4,3] is as max(a)min(a)=70=75max(a)−min(a)=7−0=7≥5.

You are given an array aa of nn integers. Find some interesting nonempty subarray of aa, or tell that it doesn't exist.

An array bb is a subarray of an array aa if bb can be obtained from aa by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

Input

The first line contains integer number tt (1t100001≤t≤10000). Then tt test cases follow.

The first line of each test case contains a single integer nn (2n21052≤n≤2⋅105) — the length of the array.

The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (0ai1090≤ai≤109) — the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 21052⋅105.

Output

For each test case, output "NO" in a separate line if there is no interesting nonempty subarray in aa.

Otherwise, output "YES" in a separate line. In the next line, output two integers ll and rr (1lrn1≤l≤r≤n) — bounds of the chosen subarray. If there are multiple answers, print any.

You can print each letter in any case (upper or lower).

Example
input
3
5
1 2 3 4 5
4
2 0 1 9
2
2019 2020
output
NO
YES
1 4
NO
Note

In the second test case of the example, one of the interesting subarrays is a=[2,0,1,9]a=[2,0,1,9]: max(a)min(a)=90=94max(a)−min(a)=9−0=9≥4.

复制代码
/*
    只要存在合法字串,那么一定存在长度为2的合法子串
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 200010
using namespace std;
int a[maxn],n;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        if(n==1){
            puts("NO");
            continue;
        }
        bool flag=0;
        for(int i=2;i<=n;i++){
            if(abs(a[i]-a[i-1])>=2){
                flag=1;
                puts("YES");
                printf("%d %d\n",i-1,i);
                break;
            }
        }
        if(!flag)puts("NO");
    }
    return 0;
} 
复制代码

 

posted @   Echo宝贝儿  阅读(202)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
历史上的今天:
2017-02-12 2017.2.10测试 藏妹子之处
点击右上角即可分享
微信分享提示