• B. Interesting Subarray


    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)=4−1=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)=7−0=7≥5max(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 (1≤t≤100001≤t≤10000). Then tt test cases follow.

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

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

    It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅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 (1≤l≤r≤n1≤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

    Copy

    3
    5
    1 2 3 4 5
    4
    2 0 1 9
    2
    2019 2020
    

    output

    Copy

    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)=9−0=9≥4max(a)−min(a)=9−0=9≥4.

    =========================================================================

    钻牛角尖的题,k越小越好,那就取2,判断连续两个数字是否是绝对值相差2

    1. # include
    2. # include
    3. # include
    4. # include
    5. # include
    6. using namespace std;
    7. typedef long long int ll;
    8. int main ()
    9. {
    10. int t;
    11. cin>>t;
    12. while(t--)
    13. {
    14. int n,pre,x,flag=0,ans1,ans2;
    15. cin>>n>>pre;
    16. for(int i=2;i<=n;i++)
    17. {
    18. cin>>x;
    19. if(abs(x-pre)>=2)
    20. {
    21. ans1=i-1;
    22. ans2=i;
    23. flag=1;
    24. }
    25. pre=x;
    26. }
    27. if(flag)
    28. {
    29. cout<<"YES"<
    30. cout<" "<
    31. }
    32. else
    33. {
    34. cout<<"NO"<
    35. }
    36. }
    37. return 0;
    38. }

  • 相关阅读:
    CSS - 深入理解选择器的使用方式
    [spring]spring详细总结
    Flutter导入安卓第三方库报错:Flutter Could not find method implementation() 的可能原因及解决办法
    Windows系统中苹果ipa上传到App Store Connect
    当我开始思考人生、职业、兴趣
    Android之getSystemService方法实现详解
    基于中国新能源汽车税收政策下成都市场发展路线研究
    Python数据结构(队列)
    解锁潜力:创建支持Actions接口调用的高级GPTs
    每日一题:LeetCode-589.N叉树的前序遍历
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126305675