jeudi 29 juin 2017

Code doesn't seem to work for larger inputs, works fine for smaller ones

While solving this question,my code doesn't seem to work for larger inputs like 100000, but seems to work fine for smaller inputs. Here's the code :

int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
long long int n, h;
cin>>n;
long long int count=0;
long long int i,j;
long long int arr[n];
for(i=0;i<n;i++)
{
    cin>>arr[i];
    //cout<<arr[i]<<" ";
}
h = arr[0];
for(i=0;i<n;i++)
{
    if (arr[i]>=h)
    {
        h=arr[i];
        for(j=i;j<n;j++)
        { if (arr[j]<h)
                count++;
        }       


    }
}
cout<<(n-count);
//cout<<h;    
return 0;
}

Can anyone please help me out? Thank you.

Aucun commentaire:

Enregistrer un commentaire