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
- # include
- # include
- # include
- # include
- # include
- using namespace std;
- typedef long long int ll;
-
- int main ()
- {
-
- int t;
-
- cin>>t;
-
- while(t--)
- {
- int n,pre,x,flag=0,ans1,ans2;
- cin>>n>>pre;
-
- for(int i=2;i<=n;i++)
- {
- cin>>x;
-
- if(abs(x-pre)>=2)
- {
- ans1=i-1;
- ans2=i;
- flag=1;
- }
- pre=x;
- }
-
- if(flag)
- {
- cout<<"YES"<
- cout<
" "< - }
- else
- {
- cout<<"NO"<
- }
- }
-
- return 0;
- }
-
相关阅读:
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
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU