-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheAmazingRace.cpp
59 lines (59 loc) · 1.2 KB
/
TheAmazingRace.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
int main()
{
int testcases;
cin>>testcases;
while(testcases > 0)
{
long int size;
cin>>size;
long int height[size];
for(long int i=0;i<size;i++)
{
cin>>height[i];
}
long int pos = 1;
long int max = 0;
for(long int i=0;i<size;i++)
{
long int cars_around = 0;
for(long int j=i-1; j>=0; j--)
{
if(height[j]<height[i])
{
cars_around++;
}
else
{
cars_around++;
break;
}
}
for(long int j=i+1; j<size; j++)
{
if(height[j]<height[i])
{
cars_around++;
}
else
{
cars_around++;
break;
}
}
long temp = 0;
temp = cars_around*(i+1);
//cout<<"\nPos : "<<i+1<<" Height : "<<height[i]<<" cars around : "<<cars_around<<" temp : "<<temp;
if(temp > max)
{
max = temp;
pos = i+1;
}
//cout<<"\n Max : "<<max;
}
cout<<pos<<"\n";
testcases--;
}
return 0;
}