Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[100100];
  6.  
  7. int main(){
  8. int n, m, k, knul;
  9. m = 0;
  10. k = 0;
  11. knul = 0;
  12. cin >> n;
  13. for (int i = 0; i < n; ++i){
  14. cin >> a[i];
  15. if (a[i] > 1){
  16. while (a[i] != 1){
  17. m += 1;
  18. a[i] -= 1;
  19. }
  20. }
  21. if (a[i] <= -1){
  22. while (a[i] != -1){
  23. m +=1;
  24. a[i] +=1;
  25. }
  26. k+=1;
  27. }
  28. if (a[i] == 0){
  29. knul+=1;
  30. }
  31. }
  32. if (k > 0 && knul > 0 && k%2!=0){
  33. m+=1;
  34. k+=1;
  35. knul-=1;
  36. }
  37. if (k > 0 && knul == 0 && k%2 != 0){
  38. m+=2;
  39. k-=1;
  40. }
  41. m += knul;
  42. cout << m << endl;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement