Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. using namespace std;
  4.  
  5. int vv [111];
  6. int ans [111];
  7.  
  8. int main()
  9. {
  10. int n;
  11. cin >> n;
  12. for (int i = 0; i < n; i ++)
  13. {
  14. int a;
  15. cin >> a;
  16. vv[i] = a;
  17. }
  18. for (int i = 0; i < n - 1; i ++)
  19. for (int j = i + 1; j < n; j ++)
  20. if (vv[i] > vv[j])
  21. swap (vv[i], vv[j]);
  22. for (int i = n - 1; i >= 0; i --)
  23. {
  24. ans[i] = min(ans[i + 1], ans[i + 2]) + abs(vv[i + 1] - vv[i]);
  25. }
  26. cout << ans[0];
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement