fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t, n, r;
  6. cin >> t;
  7. while(t--) {
  8. string s;
  9. cin >> n;
  10. vector<int> v(n+1, 0);
  11. for(int i=0; i<n; i++) {
  12. cin >> s >> r;
  13. v[r]++;
  14. }
  15. int res = 0;
  16. int rank = 1;
  17. for(int i=1; i<=n; i++) {
  18. while(v[i] > 0) {
  19. res += abs(i-rank);
  20. rank++;
  21. v[i]--;
  22. }
  23. }
  24. cout << res << endl;
  25. v.clear();
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 4496KB
stdin
2

7
noobz 1
llamas 2
Winn3rz 2
5thwheel 1
NotoricCoders 5
StrangeCase 7
WhoKnows 7

3
ThreeHeadedMonkey 1
MoscowSUx13 1
NeedForSuccess 1
stdout
5
3