forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS10E.cpp
96 lines (82 loc) · 2.26 KB
/
S10E.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*Chef wants to buy a new phone, but he is not willing to spend a lot of money.
Instead, he checks the price of his chosen model everyday and waits for the price
to drop to an acceptable value. So far, he has observed the price for N days
(numbere 1 through N); for each valid i, the price on the i-th day was Pi dollars.
On each day, Chef considers the price of the phone to be good if it is strictly
smaller than all the prices he has observed during the previous five days. If
there is no record of the price on some of the previous five days (because Chef
has not started checking the price on that day yet), then Chef simply ignores
that previous day ― we could say that he considers the price on that day to be
infinite.
Now, Chef is wondering ― on how many days has he considered the price to be good?
Find the number of these days.
Input
The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
The first line of each test case contains a single integer N.
The second line contains N space-separated integers P1,P2,…,PN.
Output
For each test case, print a single line containing one integer ― the number of
days with a good price.
Constraints
1≤T≤100
7≤N≤100
350≤Pi≤750 for each valid i
Subtasks
Subtask #1 (30 points): N=7
Subtask #2 (70 points): original constraints
Example Input
1
7
375 750 723 662 647 656 619
Example Output
2
Explanation
Example case 1: Chef considers the price to be good on day 1, because he has not
observed any prices on the previous days. The prices on days 2,3,4,5,6 are not
considered good because they are greater than the price on day 1. Finally, the
price on day 7 is considered good because it is smaller than all of the prices
on days 2,3,4,5,6.*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[n],i,j,k,temp;
for(i=0;i<n;i++)
cin>>a[i];
k=0;
for(i=0;i<n;i++)
{
if(i<=4)
{
temp=INT_MAX;
for(j=0;j<i;j++)
{
if(a[j]<temp)
temp=a[j];
}
if(temp>a[i])
k++;
}
else
{
temp=a[i-5];
for(j=i-5;j<i;j++)
{
if(a[j]<temp)
temp=a[j];
}
if(temp>a[i])
k++;
}
}
cout<<k<<endl;
}
return 0;
}