forked from ShivamDubey7/Competitive-Programming-Algos
-
Notifications
You must be signed in to change notification settings - Fork 315
/
Copy pathArrival of general codeforces
64 lines (53 loc) · 1.29 KB
/
Arrival of general codeforces
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
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
int main(){
int n,max=0,min=0,count=0,temp,i;
cin >>n;
int arr[n];
//cout <<n;
cin >>arr[0];
min=arr[0];
max=arr[0];
// cout <<arr[0];
for ( i=1;i<n;i++){
// cout <<i<<endl;
//cout <<n<<" ";
cin >>arr[i];
// cout <<endl<<arr[i];
}
//cout <<n;
//cout <<arr[n-1];
/*for (int i=0;i<n;i++){
cout <<arr[i]<<" ";
}*/
for (int i=1;i<n;i++){
if (arr[i]>max){
max=arr[i];
}
if (arr[i]<min){
min=arr[i];
}
}
for (int i=0;i<n;i++){
if (arr[0]!=max){
for (int j=0;arr[j]!=max;j++){
temp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;
count++;
}
}
}
for (int i=0;i<n;i++){
if(arr[n-1]!=min){
for (int j=0;arr[j]!=min;j++){
temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;
count++;
}
}
}
//cout <<count;
return 0;
}