fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n,i,j;
  7. int arr[100005];
  8. scanf("%d" ,&n);
  9. for(i=0;i<n;i++)
  10. scanf("%d" ,&arr[i]);
  11. int k=2*n-2;
  12. int count=0;
  13. for(i=1;i<=k;i++)
  14. {
  15. int flg=1;
  16. for(j=0;j<n;j++)
  17. {
  18. if(arr[j]==i&&flg)
  19. {
  20. flg=0;
  21. continue;
  22. }
  23. if(arr[j]==i&&(!flg))
  24. {
  25. arr[j]+=1;
  26. count++;}}
  27. }
  28. printf("%d" ,count);
  29. return 0;
  30. }
Success #stdin #stdout 0s 3740KB
stdin
4
2 6 4 5
stdout
Standard output is empty