forked from shikaruki/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Carvans Problem Solution
51 lines (42 loc) · 2.22 KB
/
Carvans Problem Solution
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
Problem :-
Most problems on CodeChef highlight chef's love for food and cooking but little is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of the circuit was a long straight road. It was impossible for a car to overtake other cars on this segment. Therefore, a car had to lower down its speed if there was a slower car in front of it. While watching the race, Chef started to wonder how many cars were moving at their maximum speed.
Formally, you're given the maximum speed of N cars in the order they entered the long straight segment of the circuit. Each car prefers to move at its maximum speed. If that's not possible because of the front car being slow, it might have to lower its speed. It still moves at the fastest possible speed while avoiding any collisions. For the purpose of this problem, you can assume that the straight segment is infinitely long.
Count the number of cars which were moving at their maximum speed on the straight segment.
Input :-
The first line of the input contains a single integer T denoting the number of test cases to follow. Description of each test case contains 2 lines. The first of these lines contain a single integer N, the number of cars. The second line contains N space separated integers, denoting the maximum speed of the cars in the order they entered the long straight segment.
Output :-
For each test case, output a single line containing the number of cars which were moving at their maximum speed on the segment.
Example :-
Input :-
3
1
10
3
8 3 6
5
4 5 1 2 3
Output :-
1
2
2
Constraints :-
1 ≤ T ≤ 100
1 ≤ N ≤ 10,000
All speeds are distinct positive integers that fit in a 32 bit signed integer.
Each input file will not be larger than 4 MB (4,000,000,000 bytes) in size.
WARNING! The input files are very large. Use faster I/O.
Solution :-
num = int(input())
carSpeed = list
for i in range(num):
# give second input no of cars
carNo = int(input())
carSpeed = list(map(int, input().split()))
MaxSpeed = carSpeed[0]
count = 0
for x in carSpeed:
if(MaxSpeed >= x):
count = count+1
MaxSpeed = x
print(count)
#num = num-1