-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBAISED.cpp
46 lines (31 loc) · 1.02 KB
/
BAISED.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// AC, Algo : Sorting.
/*
Helpful Link : http://www.cplusplus.com/reference/algorithm/sort/
*/
// For any clarifications, contact me at : osinha6792@gmail.com
#include <cstdio>
#include <algorithm>
using namespace std ;
int main( )
{
long long t , n , i , bad ;
char str[10000] ;
scanf("%lld",&t) ;
while( t-- )
{
scanf("%lld",&n) ;
long long a[n+1] ;
for( i = 1 ; i <= n ; i++ )
scanf("%s %lld",str,&a[i]) ;
sort( a + 1 , a + n + 1 ) ;
for( bad = 0 , i = 1 ; i <= n ; i++ )
{
if( i - a[i] < 0 )
bad += ( a[i] - i ) ;
else
bad += ( i - a[i] ) ;
}
printf("%lld\n",bad) ;
}
return 0 ;
}