Trying to submit on SPOJ giving wrong answer

I am submitting a similar code on SPOJ but it’s showing wrong answer. Here is my code,
#include
#include
#include
#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n+1]={0};
//memset(arr,0,sizeof(arr));
for(int i=0;i<n;i++){
string s;
int x;
cin>>s>>x;
arr[x]++;
}
int badness=0;
int currank=1;
for(int i=1;i<=n;i++){
while(arr[i]!=0){
badness+=(abs(i-currank));
arr[i]–;
currank++;
}
}
cout<<badness<<endl;
}
return 0;
}

please share code in cb ide
and also provide spoj question link

take this as n+10
also u might be wanting to convert int to long int

#include <bits/stdc++.h>
using namespace std;

int main()
{
    // your code goes here
    int t;
    cin >> t;
    while (t--)
    {
        long int  n;
        cin >> n;
        long int  arr[n+1] = {0};
        string s;
        long int  x;
        //memset(arr,0,sizeof(arr));
        for (long int  i = 0; i < n; i++)
        {

            cin >> s >> x;
            arr[x]++;
        }
        long int  badness = 0;
        long int  currank = 1;
        for (long int  i =1; i <= n; i++)
        {
            while (arr[i] != 0)
            {
                badness += (abs(i - currank));
                arr[i]--;
                currank++;
            }
        }
        cout << badness << endl;
    }
    return 0;
}```
all test cases passed for me