A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms

 CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!)




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 1i,jn such that, for all 1kn, the following equality holds:

|aiak|+|akaj|=|aiaj|,
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 t (1t1000) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer n (1n105) — the length of the array.

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

The sum of n for all test cases is at most 2105.

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|a2a1|+|a1a3|=|25|+|57|=5=|27|=|a2a3|,
  • k=2|a2a2|+|a2a3|=|22|+|27|=5=|27|=|a2a3|,
  • k=3|a2a3|+|a3a3|=|27|+|77|=5=|27|=|a2a3|.

solution:
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #define ll long long
  5. using namespace std;
  6.  
  7. void solve()
  8. {
  9. ll n;
  10. cin >> n;
  11. vector<int> v(n);
  12. for (ll i = 0; i < n; i++)
  13. {
  14. cin >> v[i];
  15. }
  16. ll minIndex = min_element(v.begin(), v.end()) - v.begin();
  17. ll maxIndex = max_element(v.begin(), v.end()) - v.begin();
  18. cout << minIndex+1 << " " << maxIndex+1 << "\n";
  19. }
  20.  
  21. int main()
  22. {
  23. int t;
  24. cin >> t;
  25. while (t--)
  26. {
  27. solve();
  28. }
  29. return 0;
  30. }

No comments:

Post a Comment