CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!)
You are given an array of positive integers. A good pair is a pair of indices with such that, for all , the following equality holds:
Find a good pair. Note that can be equal to .
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer () — the length of the array.
The second line of each test case contains integers () where is the -th element of the array.
The sum of for all test cases is at most .
For each test case, print a single line with two space-separated indices and which form a good pair of the array. The case is allowed. It can be shown that such a pair always exists. If there are multiple good pairs, print any of them.
3 3 5 2 7 5 1 4 2 2 3 1 2
2 3 1 2 1 1
In the first case, for and the equality holds true for all :
- : ,
- : ,
- : .
- #include<iostream>
- #include<algorithm>
- #include<vector>
- #define ll long long
- using namespace std;
- void solve()
- {
- ll n;
- cin >> n;
- vector<int> v(n);
- for (ll i = 0; i < n; i++)
- {
- cin >> v[i];
- }
- ll minIndex = min_element(v.begin(), v.end()) - v.begin();
- ll maxIndex = max_element(v.begin(), v.end()) - v.begin();
- cout << minIndex+1 << " " << maxIndex+1 << "\n";
- }
- int main()
- {
- int t;
- cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
No comments:
Post a Comment