The test case is giving correct output, but the code is not getting submitted on SPOJ. It says wrong answer.
Please help me identify what is wrong in my code.
#include<iostream>
#include<cstring>
using namespace std;
int biased_standings(int N, int h[]){
int avail_rank = 1;
int sum = 0;
for(int i=1; i<=N; i++){
while(h[i]){
h[i]--;
sum += abs(avail_rank - i);
avail_rank++;
}
}
return sum;
}
int main(){
int h[100000] = {0};
int t;
cin>>t;
while(t--){
memset(h,0,sizeof(h));
int N;
cin>>N; // N teams
for(int i=0; i<N; i++){
string team_name;
int rank;
cin>>team_name>>rank;
h[rank]++;
}
cout<<biased_standings(N,h)<<endl;
}
return 0;
}