加载中...

Codeforces1656A题 Good Pairs

Codeforces1656A题 Good Pairs

题目

A. Good Pairs
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

You are given an array a1,a2,…,an of positive integers. A good pair is a pair of indices (i,j) with 1≤i,j≤n such that, for all 1≤k≤n, the following equality holds:

|ai−ak|+|ak−aj|=|ai−aj|,

where |x| denotes the absolute value of x.

Find a good pair. Note that i can be equal to j.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤10^5) — the length of the array.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤10^9) where ai is the i-th element of the array.

The sum of n for all test cases is at most 2⋅10^5.

Output

For each test case, print a single line with two space-separated indices i and j which form a good pair of the array. The case i=j is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.

Example

input

Copy

3
3
5 2 7
5
1 4 2 2 3
1
2

output

Copy

2 3
1 2
1 1

Note

In the first case, for i=2 and j=3 the equality holds true for all k:

  • k=1:|a2−a1|+|a1−a3|=|2−5|+|5−7|=5=|2−7|=|a2−a3|
  • k=2:|a2−a2|+|a2−a3|=|2−2|+|2−7|=5=|2−7|=|a2−a3|
  • k=3:|a2−a3|+|a3−a3|=|2−7|+|7−7|=5=|2−7|=|a2−a3|

思路

数组中最小的元素做ai,最大的元素做aj

代码

#include<iostream>

using namespace std;

int times;
int n;
int a[100005];

int main()
{
	cin>>times;
	while(times--)
	{
		cin>>n;
		int maxn=-1,minn=1000000005;
		int max_index=0,min_index=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]>maxn)
			{
				maxn=a[i];
				max_index=i;
			}
			if(a[i]<minn)
			{
				minn=a[i];
				min_index=i;
			}
		}
		cout<<min_index<<' '<<max_index<<endl;
	}
	return 0;
} 
posted @ 2022-03-25 12:51  我没有bug  阅读(62)  评论(0编辑  收藏  举报