CF1656A.Good Pairs
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
|a\_i - a\_k| + |a\_k - a\_j| = |a\_i - a\_j|, $$ where $|x|$ denotes the absolute value of $x$. Find a good pair. Note that $i$ can be equal to $j$. 给你一个由正整数组成的数组 $a_1, a_2, \ldots, a_n$。一个“好对”是指满足 $1 \leq i, j \leq n$ 的下标对 $(i, j)$,使得对所有 $1 \leq k \leq n$,以下等式成立: $$ |a\_i - a\_k| + |a\_k - a\_j| = |a\_i - a\_j|, $$ 其中 $|x|$ 表示 $x$ 的绝对值。 请找出一个好对。注意,$i$ 可以等于 $j$。输入格式
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤105) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) where ai is the i-th element of the array.
The sum of n for all test cases is at most 2⋅105.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),其中 ai 表示数组的第 i 个元素。
所有测试用例的 n 值之和不超过 2⋅105。
输出格式
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.
对于每个测试用例,输出一行,包含两个以空格分隔的下标 i 和 j,它们构成该数组的一个“好”数对。允许 i=j。可以证明这样的数对一定存在。如果存在多个“好”数对,输出其中任意一个即可。
输入输出样例
输入#1
3 3 5 2 7 5 1 4 2 2 3 1 2
输出#1
2 3 1 2 1 1
说明/提示
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∣.
在第一种情况下,当 i=2 且 j=3 时,该等式对所有 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测评打分。不知道怎么写?