fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cin>>n;
  9. vector<int> customer (n, 0);
  10. for(int i=0; i<n; i++) {
  11. cin>>customer[i];
  12. }
  13.  
  14. sort(customer.begin(),customer.end());
  15. long count = 0;
  16. for(int i=n-1; i>=0; i--) {
  17. count += abs(i+1-customer[i] );
  18. }
  19. cout<<count<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5500KB
stdin
4
4 4 4 4
stdout
6