Untitled

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

int main()
{
	int n = 0;
	std::cin >> n;
	int max = 0;
	int maxID = 0;
	int min = 100;
	int minID = 0;
	int tmp = 0;

	for (int i = 0; i < n; i++) {
		std::cin >> tmp;
		if (tmp <= min) {
			min = tmp;
			minID = i;
		}
		if (tmp > max) {
			max = tmp;
			maxID = i;
		}
	}

	std::cout << maxID + n - minID - 1 - int(maxID > minID);
}
Leave a Comment