-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Stone_Game.cpp
More file actions
42 lines (41 loc) · 821 Bytes
/
A_Stone_Game.cpp
File metadata and controls
42 lines (41 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll n)
{
int arr[n];
int mini = -1, maxi = -1;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
if (mini == -1)
mini = i;
if (maxi == -1)
maxi = i;
if (arr[mini] > arr[i])
mini = i;
if (arr[maxi] < arr[i])
maxi = i;
}
int a = max(mini, maxi);
int b = max(n - mini + 1, n - maxi + 1);
int ans = min(a, b);
int c = min(mini, maxi) + min(n - mini + 1, n - maxi + 1);
ans = min(ans, c);
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
solve(n);
}
return 0;
}