Carvans.Why i am getting wrong answer. Please help me with this

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t= sc.nextInt();
while(t>0)
{
int n = sc.nextInt();
int speed[] = new int[n];
for(int i =0;i<n; i++)
{
speed[i] = sc.nextInt();
}
int count =1;
for(int i =0;i<n-1; i++)
{
if(speed[i]>= speed[i+1])
{
count++;
}
else{
count = count;
}
}
System.out.println(count);
t–;
}
// your code goes here
}
}

where is the question…
and in the else condition what is the meaning of again assigning count as count

Ok I get your question!!

suppose the input is 10 12 11 2 5
here first car entering the race has speed 10 so the second car having 12 speed is not counted and till now second car is moving with speed of 10 after that car with speed 11 enters now 11 is again greater than the speed of 2nd car which is 10 so it will again move with speed 10 after that 4th car with max speed 2 enters now 2 is smaller than 10 so it will move with max speed that is 2 after that 5th car enters having max speed of 5 now the 4th car has speed of 2 so it will also continue with 2

1 Like

// Created by Priyanshu
#include <bits/stdc++.h>
#define M 1000000007
#define pi 3.14159265358979323846
#define ll long long
#define lld long double
#define ld double
#define scn(str) scanf("%s",str)
#define pri(str) printf("%s\n",str)
#define deb(x) cout<<#x<<" = "<<x<<endl
#define cel(x,a) ((x+a-1)/a)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define si set
#define sii set
#define vi vector
#define vl vector
#define vpi vector
#define vpl vector
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mina *min_element
#define mama *max_element
#define bsrch binary_search
#define ufor for
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ps(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define F first
#define S second
#define lcm(m, n) ((m/__gcd(m,n))*n)
#define inp(ar, n) for(int ele=0; ele<n; ele++)ar[ele]=read();
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define all(v) v.begin(), v.end()
#define wws(k) ww(k), putchar(’ ‘)
inline ll read() {ll sign = 1; ll x = 0; char ch; while (!isdigit(ch = getchar())) if (ch == ‘-’) sign = -1; while (isdigit(ch)) x = x * 10 + ch - ‘0’, ch = getchar(); return x * sign;}
inline void ww(ll k) { if (k < 0) putchar(’-’), k *= -1; char ch[20]; int num = 0; while (k)ch[++num] = k % 10, k /= 10; if (num == 0) ch[++num] = 0; while (num)putchar(ch[num–] + ‘0’);}

using namespace std;
const int N = 1e5 + 4;

inline void wonl() {putchar(’\n’);}

template <typename T, typename… V>
inline void wonl(T t, V… v) {ww(t); if (sizeof…(v))putchar(’ '); wonl(v…);}

int main()
{
// fast;
// clock_t time_req = clock();

int t = read();
while (t--) {
    int n = read(), ar[n], cnt = 0;
    inp(ar, n);
    int speed = ar[0];


    for (int i = 0; i < n; i++)
        if (speed >= ar[i])
            cnt++, speed = ar[i];


    wonl(cnt);
}


// time_req = clock() - time_req;
// cout << (float)time_req / CLOCKS_PER_SEC;
return 0;

}

Thank you sir .You really explained well:).

1 Like

Got it. Thank you sir.

1 Like