http://www.codechef.com/problems/BESTBATS getting wa. here is my code: http://ideone.com/E8AnqD
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int cmp(const void *a, const void *b) {
return(*(int*)b - *(int*)a);
}
unsigned int fact(unsigned int a) {
return (a==1 || a==0) ? 1 : fact(a-1)*a;
}
int main() {
int t, p[11], k, tot, act, pas, el, r;
scanf("%d", &t);
while(t--) {
act=0; pas=0; tot=0; el=0;
for(int i=0; i<11; i++) scanf("%d", &p[i]);
scanf("%d", &k);
qsort(p, 11, sizeof(int), cmp);
el=p[10-k];
for(int i=10; i>k-1; i--) if(el==p[i]) act++;
for(int i=k-1; i>0; i--) if(el==p[i]) pas++;
tot=act+pas; r=0; r=fact(tot)/(fact(act)*fact(tot-act));
printf("%d\n", r);
}
return 0;
}