c - runs fine on IDE but gives Runtime Error(SIGSEGV) on submitting -


https://www.codechef.com/problems/cleanup/

after long , successful day of preparing food banquet, time clean up. there list of n jobs before kitchen can closed night. these jobs indexed 1 n.

most of cooks have left , chef , assistant left clean up. thankfully, of cooks took care of of jobs before left subset of n jobs remain. chef , assistant divide remaining jobs in following manner. chef takes unfinished job least index, assistant takes unfinished job second least index, chef takes unfinished job third least index, etc. is, if unfinished jobs listed in increasing order of index chef take every other 1 starting first job in list , assistant take every other 1 starting second job on in list.

the cooks logged jobs finished before left. unfortunately, these jobs not recorded in particular order. given unsorted list of finished jobs, determine jobs chef must complete , jobs assitant must complete before closing kitchen evening. input

the first line contains single integer t ≤ 50 indicating number of test cases follow. each test case consists of 2 lines. first line contains 2 numbers n,m satisfying 0 ≤ m ≤ n ≤ 1000. here, n total number of jobs must completed before closing , m number of jobs have been completed. second line contains list of m distinct integers between 1 , n. these indices of jobs have been completed. consecutive integers separated single space. output

the output each test case consists of 2 lines. first line list of indices of jobs assigned chef. second line list of indices of jobs assigned assistant. both lists must appear in increasing order of indices , consecutive integers should separated single space. if either chef or assistant not assigned jobs, corresponding line should blank. example

input:

3 6 3 2 4 1 3 2 3 2 8 2 3 8 

output:

3 6 5 1  1 4 6 2 5 7 

code:

#include<stdio.h> int main() {     int t=0,n=0,m=0,i=0,count=0,val=0,j=0;     int arr[100]={0};     scanf("%d",&t);     while(t--)     {         scanf("%d",&n);         scanf("%d",&m);         for(i=0;i<m;i++)         {            scanf("%d",&arr[i]);         }          val=0;         for(i=1;i<=n;i++)         {                count=0;              for(j=0;j<m;j++)              {                  if(i==arr[j])                  {                      count=1;                      break;                  }              }              if(count==0)              {                  val=val+1;                  if(val%2!=0)                  printf("%d ",i);              }         }         printf("\n");         val=0;         for(i=1;i<=n;i++)         {                count=0;              for(j=0;j<m;j++)              {                  if(i==arr[j])                  {                      count=1;                      break;                  }              }              if(count==0)              {                  val=val+1;                  if(val%2==0&&val!=0)                  printf("%d ",i);              }         }         printf("\n");     }     return 0; }   

runs fine on ide gives runtime error(sigsegv) on submitting .. pls help

the first line contains 2 numbers n,m satisfying 0 ≤ m ≤ n ≤ 1000

that indicates me that

int arr[100]={0}; 

is not sufficient test cases. change to:

int arr[1000]={0}; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -