ProgMe

Untitled

Feb 24th, 2021
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5.  
  6. bool sorted(int a[], int sz){
  7. for(int i = 1; i <= sz; i++)
  8. if(a[i] != i)
  9. return false;
  10. return true;
  11. }
  12.  
  13. int32_t main(){
  14. int n;
  15. cin >> n;
  16. int h[n + 1];
  17. for(int i = 1; i <= n; i++)
  18. cin >> h[i];
  19. if(sorted(h, n)) {
  20. cout << "-1 -1";
  21. return 0;
  22. }
  23. pair<int, int> ans = {1, 2};
  24. int dlt = abs(h[ans.first] - ans.first) + abs(h[ans.second] - ans.second) - abs(h[ans.first] - ans.second) - abs(h[ans.second] - ans.first);
  25. for(int i = 1; i <= n; i++)
  26. for(int j = i + 1; j <= n; j++)
  27. if(dlt < abs(h[i] - i) + abs(h[j] - j) - abs(h[i] - j) - abs(h[j] - i))
  28. ans = {i, j}, dlt = abs(h[i] - i) + abs(h[j] - j) - abs(h[i] - j) - abs(h[j] - i);
  29. cout << ans.first << ' ' << ans.second;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment