A. Good Pairs

本文介绍了一个Codeforces上的算法题目——寻找数组中的GoodPair。通过找出数组中的最大值和最小值的位置来快速解决该问题,实现简单且高效。

Problem - A - Codeforces

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,…,ana1,a2,…,an of positive integers. A good pair is a pair of indices (i,j)(i,j) with 1≤i,j≤n1≤i,j≤n such that, for all 1≤k≤n1≤k≤n, the following equality holds:

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

where |x||x| denotes the absolute value of xx.

Find a good pair. Note that ii can be equal to jj.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤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≤1051≤n≤105) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) where aiai is the ii-th element of the array.

The sum of nn for all test cases is at most 2⋅1052⋅105.

Output

For each test case, print a single line with two space-separated indices ii and jj which form a good pair of the array. The case i=ji=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=2i=2 and j=3j=3 the equality holds true for all kk:

  • k=1k=1: |a2−a1|+|a1−a3|=|2−5|+|5−7|=5=|2−7|=|a2−a3||a2−a1|+|a1−a3|=|2−5|+|5−7|=5=|2−7|=|a2−a3|,
  • k=2k=2: |a2−a2|+|a2−a3|=|2−2|+|2−7|=5=|2−7|=|a2−a3||a2−a2|+|a2−a3|=|2−2|+|2−7|=5=|2−7|=|a2−a3|,
  • k=3k=3: |a2−a3|+|a3−a3|=|2−7|+|7−7|=5=|2−7|=|a2−a3||a2−a3|+|a3−a3|=|2−7|+|7−7|=5=|2−7|=|a2−a3|.
import sys
import math
#import numpy as np
#sys.stdin = open("in.txt", "r")
 
T = int(input())
for _ in range(T):
    n= int(input())
    arr=[int(i) for i in input().split()]
    maxi=0
    mini=0
    for i in range(len(arr)):
        if arr[maxi]<arr[i]:
            maxi=i
        if arr[mini]>arr[i]:
            mini=i
    if maxi>mini:
        maxi,mini=mini,maxi
    print('{} {}'.format(maxi+1,mini+1))

最大最小数满足这个条件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值