Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
493 B
0
Indexable
Never
#include <iostream>

int main() {
    
    int n;
    int id;
    int max = -1,min = 101;
    int maxId,minId;
    int height;
    std::cin >> n;
    for (id = 0; id < n; id++) {
        std::cin >> height;
        if (height > max) {
            max = height;
            maxId = id;
        }if (height <= min) {
            min = height;
            minId = id;
        }
    }if (maxId > minId) {
        minId += 1;
    }
    std::cout << (n - 1 - minId) + maxId;
}
Leave a Comment