-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF-144A.cpp
More file actions
42 lines (32 loc) · 685 Bytes
/
Copy pathCF-144A.cpp
File metadata and controls
42 lines (32 loc) · 685 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 <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> line(n);
int taller = 0;
int taller_idx = -1;
int shorter = 1000;
int shorter_idx = -1;
for (int i = 0; i < n; i++) {
int h;
cin >> h;
line[i] = h;
if (h > taller) {
taller = h;
taller_idx = i;
}
if (h <= shorter) {
shorter = h;
shorter_idx = i;
}
}
int swaps = taller_idx + n - 1 - shorter_idx;
if (taller_idx > shorter_idx) {
swaps--;
}
cout << swaps << '\n';
return 0;
}