A - Excellent Team

时间:2023-12-15 08:29:50

Description

Gibbs: Next!
First Pirate: My wife ran off with my dog and I'm drunk for a month.

Gibbs: Perfect. Next!

Second Pirate: Me have one arm and a bum leg.

Gibbs: It's the crow's nest for you. Next!
In Tortuga the Captain Jack Sparrow and Will Turner set up an excellent
team. And now Jack wants to elect a captain's mate — the most worthy
pirate in the new crew, who has fewer disadvantages and can be a role
model for the rest.
Without thinking a lot Jack decided to use the following uncomplicated
plan to choose the best pirate of the crew. Firstly, he ranks n
contenders in one long row, beckons the first one and this first pirate
is a current contender to be the mate. Then Jack walks along the row and
stares at everybody one by one. He compares the regular pirate with the
current contender and if he sees that the regular pirate has fewer
disadvantages, then he changes the current contendor to the regular
pirate. In the end of this process the new mate will stand near Jack.
Will knows about Jack’s plan and wants to count what pirate will have
most comparisons while Jack elects. Let’s help Will with his
calculations.

Input

The first line contains an integer n that is the number of pirates in the crew (1 ≤
n ≤ 10 5). Next line contains n integers:
a1,
a2, …,
an, where ai is the number of disadvantages of i-th contender in Jack's opinion (1 ≤
ai ≤ 10 9). The pirates are
numbered in the way they stood in the row in the beginning of the
elections. It is guaranteed that the numbers of disadvantages, which the
pirates have, are pairwise different.

Output

Output the number of a pirate who was compared with others maximal
number of times. If there are several such pirates, you can output any
of them.

Sample Input

input output
6
2 5 3 4 1 9
1
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define MM 100005
struct st
{
int num;
int count;
} a[MM]; int main()
{
int n,min,i,temp,flag,max=; while(~scanf("%d",&n))
{
max=-;
memset(a,,sizeof a);
scanf("%d",&a[].num);
min=a[].num;
temp=;
for(i=; i<n; i++)
{
scanf("%d",&a[i].num);
if(a[i].num>=min) ///相当于从后往前看了 每一次都更新一遍 最后总结
{
a[temp].count++; ///0的
a[i].count++; ///0之后的
}
else
{
min=a[i].num; ///替换
a[temp].count++; ///0的
a[i].count++;///0之后的
temp=i; ///记录编号 }
}
for(i=; i<n; i++) ///比较
{ if(max<a[i].count)
{
max=a[i].count;
flag=i+;
}
}
printf("%d\n",flag); ///输出
} return ;
}
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
int a[]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
int j=,i;
int num=;
int max=;
int ans=;
for(i=;i<=n;i++)
{ if(a[j]<a[i])
{
num++;
}
else
{
num++;
if(max<num)
{
max=num;
ans=j;
}
j=i;
num=;
}
}
if(num>max) ans=j;
printf("%d\n",ans);
}
return ;
}