Codeforces 144A

#include <stdio.h>
 
int main()
{
	int max=-1, min=1000;
	int max_ind=0, min_ind=0;
	int n;
	int line;
	scanf("%d", &n);
	int i;
	for(i=0; i<n; ++i)
	{
		scanf("%d", &line);
		if(line>max)
		{
			max=line;
			max_ind=i;
		}
		if(line<=min)
		{
			min=line;
			min_ind=i;
		}
	}
	if(min_ind==max_ind)
		printf("%d\n", 0);
	else if(min_ind>max_ind)
		printf("%d\n", max_ind-min_ind+n-1);
	else
		printf("%d\n", max_ind-min_ind+n-2);
	return 0;
}

  

上一篇:数论 a+b=n与lcm(a, b)=m


下一篇:树状数组(Binary Indexed Tree)