Pokemon

All submissions for this problem are available.
Problem description.
Ash Ketchum wants to train many Pokemons, each of which can be performed in a given time. So, he asked his friend Misty to train those Pokemons which takes minimum time to train among the remaining Pokemons. Ash will train those Pokemons which will take maximum time to train among the remaining Pokemon’s. You will be given the time of training.
Your task is to find out the number of Pokemon trained by Ash Ketchum and his friend, Misty.
Input
 The first line contains T, the number of test cases. Then T test cases follow. For each test case, there are 3 lines:
 First line contains an integer N, the number of Pokemons to be trained.
 Second line contains N integers d _{i} (1<=i<=N) the training time of all Pokémons.
 Third line gives the training time (c_{t}).
Rules
 Bugs will be mainly logical errors, including overflow issues. It will not be syntaxoriented or languagespecific.
 Since, it is an debugging contest, you will be provided a bugged solution below the Constraints section.Please, see that you must adhere to the problem code provided, make changes only where necessary.
 Online participants can copy the code and compile it using an online compiler (Eg. codechef.com/ide).
 Onsite participants will be provided Codeblocks with gcc compiler, since NO internet access other than CodeChef website will be provided.
 Once the bugs are eliminated from the code, the clean code should be submitted by using the "Submit" button on the topright corner.
 Participants will be penalised for changing the entire problem solution or writing their own solution,completely different from the buggy code as provided in the problem statement as our main intention is to test the debugging abilities of the participants.
Output
 For each test case, output a single line containing 2 integers : the number of pokemons trained by Ash and number of pokemons trained by his friend, Misty.
Constraints
 1<=T<=20
 1<=N<=1000
 1<=d_{i}<=1000
 0<=c_{t}<=1000000
Example
Input: 2 4 5 6 2 1 3 6 2 3 4 5 6 7 13
Output:
0 2
2 3
Buggy code in C:
#include < stdio.h > #include < stdlib.h > typedef unsigned long long ULL; int compare(const void *p1 ,const void *p2){ return *((int *)p1)  *((int *)p2); } int ar[1002]; int main(){ int t,n,ct,dt,i,j,k,s1,s2,a1,a2; scanf("%d",&t); while(t){ scanf("%d",&n); for( i=0 ; i < n ; i++ ) scanf( " %d " , &ar[ i ]) ; qsort(ar,n,sizeof(int),compare); scanf ( " %d " , &ct); k = ct; s1 = s2 = 0; a1 = 0 , a2 = n1; for ( i = 0 ; i <= ct ; i++ ) { if( s1 == i && s2 == i) { if ( a2 >= a1 && ( i + ar[a2] ) <= ct) s2=i + ar[ a2 ] , a2++ ; if ( a1<=a2 && ( i + ar[ a1 ] ) <= ct ) s1= i+ar[ a1 ] , a1++; else ; } else if(s1 == i){ if ( a2>=a1 && ( i + ar[ a2 ] ) <= ct) s2=i + ar[ a2 ], a2++; else ; } else if(s2 == i){ if ( a1<=a2 && ( i + ar[a1] )<=ct) s1 = i +ar[ a1 ], a1++; else ; } } printf( " %d %d \n ", n  a2  1,a1); } return 0; }
Author:  roy_soumya 
Tags  roy_soumya 
Date Added:  1032016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, PYP3 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 