Why it is giving tle

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

int abs(int a, int b) {
if(a - b > 0) {
return a - b;
}
else {
return b - a;
}
}

int main() {
int t;
cin >> t;
int cnt[100000] = {0};
while(t–) {
string name;
int n, rank;
cin >> n;

    memset(cnt, 0, sizeof(cnt));

    for(int i = 0; i < n; i++) {
        cin >> name;
        cin >> rank;
        cnt[rank]++;
    }

    int actual_rank = 1;
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        while(cnt[i]) {
            sum += abs(actual_rank, i);
            cnt[i]--;
            actual_rank++;
        }
    }
    cout << sum << endl;
}

}

@alter
Please save your code at http://ide.codingblocks.com/ and then share link of your code here.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.