-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path354A.cpp
More file actions
52 lines (50 loc) · 938 Bytes
/
354A.cpp
File metadata and controls
52 lines (50 loc) · 938 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
43
44
45
46
47
48
49
50
51
52
#include<iostream>
using namespace std;
int main(){
int pos1,pos2;
int x,y;
int n;
int key;
int ans;
cin>>n;
x = 1;
y = n;
for(int i=0;i<n;i++){
cin>>key;
if(key==x){
pos1 = i;
}
else if(key==y){
pos2 = i;
}
}
if(pos1<pos2){
if((pos1-0)>(n-1-pos2)){
pos1 = 0;
ans = pos2 - pos1;
}
else if((pos1-0)<(n-1-pos2)){
pos2 = n-1;
ans = pos2 - pos1;
}
else{
pos2 = n-1;
ans = pos2 - pos1;
}
}
else{
if((pos2-0)>(n-1-pos1)){
pos2 = 0;
ans = pos1 - pos2;
}
else if((pos2-0)<(n-1-pos1)){
pos1 = n-1;
ans = pos1 - pos2;
}
else{
pos1 = n-1;
ans = pos1 - pos2;
}
}
cout<<ans<<endl;
}