Skip to content

Commit 14acc31

Browse files
authored
Merge pull request ashutosh97#114 from JanviMahajan14/algo-2
A phone price problem
2 parents 83d06e1 + 3951945 commit 14acc31

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

Phone price/solution.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main(){
5+
int t;
6+
cin>>t;
7+
while(t--){
8+
int n;
9+
cin>>n;int a[n];
10+
11+
for(int i=0;i<n;i++){
12+
cin>>a[i];
13+
}
14+
15+
int j=1;int good =1;int cnt=0;int t=0;
16+
17+
for(int i=1;i<n;i++){
18+
if(i>=6)t++;
19+
for(j=i-1;j>=t;j--){
20+
21+
if(a[j]>a[i]){
22+
cnt=1;}
23+
24+
else {
25+
cnt=0;
26+
break;}
27+
28+
}
29+
30+
if(cnt==1)
31+
good++;
32+
33+
}
34+
35+
cout<<good<<endl;
36+
}
37+
38+
39+
}

Phone price/statement.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
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.
2+
3+
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.
4+
5+
Now, Chef is wondering ― on how many days has he considered the price to be good? Find the number of these days.
6+
7+
Input
8+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
9+
The first line of each test case contains a single integer N.
10+
The second line contains N space-separated integers P1,P2,…,PN.
11+
12+
Output
13+
For each test case, print a single line containing one integer ― the number of days with a good price.
14+
15+
Constraints
16+
1≤T≤100
17+
7≤N≤100
18+
350≤Pi≤750 for each valid i
19+
20+
Subtasks
21+
22+
Subtask #1 (30 points): N=7
23+
Subtask #2 (70 points): original constraints
24+
25+
Example Input
26+
1
27+
7
28+
375 750 723 662 647 656 619
29+
30+
Example Output
31+
2
32+
33+
Explanation
34+
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.

0 commit comments

Comments
 (0)