Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define MAX 3000000
  4.  
  5. using namespace std;
  6.  
  7. int num[MAX];
  8.  
  9. int main(){
  10.  
  11. int n, ops = 0; cin >> n;
  12. while(n--){
  13. int el; cin >> el;
  14. if(num[el] == 0){
  15. num[el] = 1;
  16. continue;
  17. }
  18. else{
  19. int offset = 1;
  20. while(true){
  21. ops++;
  22. if(num[el + offset] == 0){
  23. num[el + offset] = 1;
  24. break;
  25. }
  26. else if(num[el - offset] == 0){
  27. num[el - offset] = 1;
  28. break;
  29. }
  30. offset++;
  31. }
  32. }
  33. }
  34.  
  35. cout << ops << endl;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement