1 / 17
Feb 2012

will someone give more test cases for me i am getting wa after running for 4 test cases by the judge.
here is my code.

include

include

using namespace std;
int main()
{
int n,i,j;
scanf("%d",&n);
printf("\n");
int a[n];
for(i=0;i scanf("%d",&a[i]);
int k;
scanf("%d",&k);
int b[k];
if(k!=0 && k!=1)
{
for(i=0;i {
for(j=0;j b[j]=a[j+i];
sort(b,b+k);
printf("%d ",b[k-1]);

        if(b[k-1]==a[j+i-1])
             {
               if((a[j+i])>(a[j+i-1]))
                 {   printf("%d ",a[j+i]);
                     i++;          
                  }
              }
         }
   }
     else
       for(i=0;i<n;i++)
          printf("%d ",a[i]);

return 0;
}
frowning frowning frowning

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,j;
    scanf("%d",&n);
    printf("\n");
    int a[n];
    for(i=0;i<n;i++)
       scanf("%d",&a[i]);
    int k;
      scanf("%d",&k);
    int b[k];
      if(k!=0 && k!=1)
       {
         for(i=0;i<n-1;i++)
            {
               for(j=0;j<k;j++)
                    b[j]=a[j+i];
                    sort(b,b+k);
                    printf("%d ",b[k-1]);   
            if(b[k-1]==a[j+i-1])
                 {
                   if((a[j+i])>(a[j+i-1]))
                     {   printf("%d ",a[j+i]);
                         i++;          
                      }
                  }
             }
       }
         else
           for(i=0;i<n;i++)
              printf("%d ",a[i]);
return 0;
}

Your code does not return the correct answer for the sample input.

Please Help !!! I am getting correct answer on so many test cases.
but spoj is giving wa .... frowning

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int a[1000020];
int main()
{
	queue<int> list;
	priority_queue<int> plist;
	int n,k;
	scanf("%d",&n);
	int temp;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	scanf("%d",&k);
    for(int i=0;i<k;i++)
{
	list.push(a[i]);
	plist.push(a[i]);	

}
	printf("%d ",plist.top());
for(int i=k;i<n;i++)
{
	if(a[i]>plist.top())
	{
		while(!plist.empty())
		plist.pop();		
	}
	plist.push(a[i]);
	if(list.front() == plist.top())
		plist.pop();
	list.pop();
	list.push(a[i]);
	if(i==n-1) printf("%d",plist.top());
	else printf("%d ",plist.top());
}
return 0;
}
1 month later

here is my code:
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
    int n,i,j;
    scanf("%d",&n);
    printf("\n");
    int a[n];
    for(i=0;i<n;i++)
       scanf("%d",&a[i]);
    int k;
      scanf("%d",&k);
    int b[k];
      if(k!=0 && k!=1)
       {
         for(i=0;i<n-k+1;i++)
            {
               for(j=0;j<k;j++)
                    b[j]=a[j+i];
                    sort(b,b+k);
                    printf("%d ",b[k-1]);   
            if(b[k-1]==a[j+i-1])
                 {
                   if((a[j+i])>(a[j+i-1]))
                     {   printf("%d ",a[j+i]);
                         i++;          
                      }
                  }
             }
       }
         else
           for(i=0;i<n;i++)
              printf("%d ",a[i]);
getch();
return 0;
}   
thanks sir for the test case.
sir i have modified my code and its giving output: 3 3 3 2 1 1 1
                                                                                for the test case given by you.
   but now also its giving WA
PLEASE HELP :oops:  :oops:  :oops:
2 months later

#include <iostream>
using namespace std;
int main() 
{
long int n,i,k,x,j,max=0;
cin>>n;
long int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
cin>>k;
for(x=0;x<n-k;x++)
{for(j=x;j<k+x;j++)
{
if(a[j]>max)
max=a[j];
}
cout<<max<<" ";
max=0;}
max=0;
for(j=n-k;j<n;j++)
{if(a[j]>max)
max=a[j];}
cout<<max<<endl;
max=0;
return 0;
}
  1. The topic that you have posted in is titled "WA in ARRAYSUB", not TLE.

  2. Do you understand why your code gets TLE?

18 days later

#include <cstdio>
using namespace std;
int main()
{
  long int n,k,i,max=0,submax=0;
  scanf("%ld",&n);
  scanf("\n");
  long int arr[n];
  for(i=0;i<n;i++)
  {
    scanf("%ld",&arr[i]);
  }
  scanf("%ld",&k);
  for(i=0;i<k;i++)
  {
    if(arr[i]>max)
    {
     submax=max;
      max=arr[i];
    }
  }
  printf("%ld ",max);
  if(k==n)
    return 0;
  while(i<n)
  {
    if(max==arr[i-k])
    {
      if(submax>arr[i])
	max=submax;
      else
	max=arr[i];
     printf("%ld ",max);
    }
    else
    {
    if(arr[i]>max) 
    {
      max=arr[i];
      printf("%ld ",max);
    }
    else
    {
      if(arr[i]<=max && arr[i]>=submax)
	submax=arr[i];
      printf("%ld ",max);
    }
  }
  i++;
}
return 0;
}

Here's my code for ARRAYSUB. It is giving correct answers for all the testcases mentioned in the comments.
I have had a lot of WA's for this.
Please helo out.

Input:

10
5 4 1 1 2 3 1 1 1 1
5

Output:

5 4 3 3 3 3

Your output:

5 3 3 3 3 3
1 year later

#include<stdio.h>
int main()
{
		long int n,i,j,m,k;
		scanf("%lu\n\n",&n);
        long int a[n];
		for(i=0;i<n;i++)
		     scanf("%lu",&a[i]);
		scanf("%lu",&k);
		long int arr[n+k-1];
		if(k>=1 && k<=n)
		{
 			for(i=0;i<=n-k;i++)
			{   long int max=a[i];
         			for(j=i+1,m=0;m<k-1;j++,m++)
				{
					if(max<a[j])
						max=a[j];
				}
				arr[i]=max;
			}
		}
		for(i=0;i<=n-k;i++)
		{
                    printf("%lu ",arr[i]);
         }
		 printf("\b");
		return 0;
}

It should say more than "error". If it doesn't say more than error please take a screenshot and post it.

How do you know it's the 5th test case? Because of the counter when the page updates?

2 months later