# CARVANS - Editorial

thats a beautiful solution

i think that in the place of : speed = max(speed,maxSpeed)
it should be : speed = min(speed,maxSpeed)

Hi,
Can anyone please suggest me. What I am doing wrong in my solution
https://www.codechef.com/LRNDSA01/submit/CARVANS

That isn’t the proper link to the solution, please check it and send the correct one

1 Like

#include
using namespace std;
void fastscan(int &number)
{
//variable to indicate sign of input number
bool negative = false;
register int c;

``````number = 0;

// extract current character from buffer
c = getchar();
if (c=='-')
{
// number is negative
negative = true;

// extract the next character from the buffer
c = getchar();
}

// Keep on extracting characters if they are integers
// i.e ASCII Value lies from '0'(48) to '9' (57)
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;

// if scanned input has a negative sign, negate the
// value of the input number
if (negative)
number *= -1;
``````

}

int main() {
int t ;
fastscan(t);
for (int i =0;i<t; i++)
{
int n ;
fastscan(n);
int a[n],z= 0;
// cout <<"Vlaue of n = "<<n<<endl;
for (int j=0 ;j<n;j++)
{
fastscan(a[j]);
}
if (n==1)
cout<<n<<endl;
else{
for (int j = 0;j<n–;j++){
// cout<<"value of j = "<<j <<endl;
// cout <<"Vlaue of a[j] = "<<a[j]<<endl;
//cout <<"Vlaue of a[j+1] = "<<a[j+1]<<endl;

``````       if (a[j]>=a[j+1]){

z++;
// cout<<z<<endl;
}
else {
a[j+1]=a[j];
}
}
cout <<z+1<<endl;
``````

}
}
}
//What is wrong in this code can anyone explain please

My Solution without using extra space

``````#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
int n, ans=0;
cin>>n;

vector<int> max_speed(n);

for(int i=0;i<n;i++) {
cin>>max_speed[i];
}
ans++;
if(n==1) {
cout<<ans<<endl;
return;
} else {
for(int i=1;i<n;i++) {
if(max_speed[i] <= max_speed[i-1]) {
ans++;
} else {
max_speed[i] = max_speed[i] - (abs(max_speed[i] - max_speed[i-1]));
}
}
}
cout<<ans<<endl;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif

ios_base::sync_with_stdio(false);
cin.tie(NULL);

int T;
cin>>T;

while(T--) {
solve();
}

return 0;
}
``````
```````#include <bits/stdc++.h>
``````

`using namespace std;`

`int main() {`
/`/ your code goes here`
` int t;`
` cin>>t;`
` while(t--){`
int n,count=0,max=0,s=0;
cin>>n;
cin>>s;
max=s;
count++;
for(int i=0;i<n-1;i++){
cin>>s;
if(s<max){
count++;
`max=s;`
`}`
`}`
`cout<<count<<endl;`
` }`
`return 0;`
`}`
`

1 Like

Hello Every One,
I have written a code for this question & tested it on sample input. It works as expected. But when I submitted the solution I am getting WA for all test cases. I have checked excepted solutions and editorials but I am not getting where I am going wrong.
My solution is Here

1 Like

Why this solution was accepted

``````n = int(input())
count = 0
for i in range(n):
c = int(input())
s = list(map(int, input().split()))
ans = s[0]
for j in range(c):
if s[j] <= ans:
ans = s[j]
count += 1
print(count)
count = 0
``````

and not this one as both seems to be the same math after all

``````n = int(input())
count = 0

for i in range(n):
c = int(input())
s = list(map(int, input().split()))
for j in range(1, c):
if s[j] >= s[j-1]:
count += 1
print(c-count)
count = 0``````